본문 바로가기

ProblemSolving45

[LeetCode 풀이/python] 48. Rotate Image (medium) 문제 설명: 2차원의 n x n 행렬 형태로 나타낸 이미지가 주어졌을 때, 해당 이미지를 시계 방향으로 90도 회전 (rotate) 하시오. 이미지 회전은 2차원 행렬 입력을 직접 수정하는 제자리 (in-place) 방식으로 이루어져야 하며, 별도의 2차원 행렬을 할당하여 이를 회전해서는 안됨. (You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise). You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matr.. 2021. 2. 16.
[LeetCode 풀이/python] 42. Trapping Rain Water (hard) 문제 설명: 0 이상의 정수 n 개로 표현되며 각 bar 의 폭이 1인 elevatation map height 가 주어졌을 때, 비가 내린 후 얼마나 많은 양의 빗물을 가둘(trap) 수 있는지 계산하시오. (Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.) 예시 1) 입력: height = [0,1,0,2,1,0,1,3,2,1,2,1] --> 출력: 6 설명: 검게 칠해진 부분이 elevation map 을 나타내며, 파랗게 칠해진 부분이 가둬진 빗물을 나타냄 예시 2) 입력: height = .. 2021. 2. 16.
[LeetCode 풀이/python] 47. Permutations II (medium) 문제 설명: 중복을 허용하는 숫자들의 집합 nums 가 주어졌을 때, 이를 통해 만들 수 있는 모든 고유한 순열(permutations) 조합을 리턴하시오. 리스트 내 조합의 순서는 무관하다. (Given a collection of numbers, nums, that might contain duplicates, return all possible unique permutations in any order.) 예시 1) 입력: nums = [1,1,2] --> 출력: [[1,1,2], [1,2,1], [2,1,1]] 예시 2) 입력: nums = [1,2,3] --> 출력: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] 제한 조건: 1 2021. 2. 16.
[LeetCode 풀이/python] 41. First Missing Positive (hard) 문제 설명: 정렬되지 않은 정수 배열 nums 가 주어졌을 때, 해당 배열에서 누락된 양의 정수 중 가장 작은 수를 찾으시오. (Given an unsorted integer array nums, find the smallest missing positive integer.) 예시 1) 입력: nums = [1,2,0] --> 출력: 3 예시 2) 입력: nums = [3,4,-1,1] --> 출력: 2 예시 3) 입력: nums = [7,8,9,11,12] --> 출력: 1 제한 조건: 0 2021. 2. 15.
[LeetCode 풀이/python] 39. Combination Sum (medium) 문제 설명: 구분되는 (중복이 없는) 정수 값으로 이루어진 배열 candidates 과 타겟 값 target 이 주어졌을 때, candidates 에서 선택한 숫자들을 더하여 타겟 값이 될 수 있는 고유한 숫자 조합을 모두 담은 리스트를 리턴하시오. 리스트 내 조합의 순서는 무관하며, candidates 에서 동일한 숫자가 선택될 수 있는 횟수에는 제한이 없다. 두 숫자 조합에서 선택된 숫자들 중 최소 하나라도 사용된 빈도가 다른 경우 이들은 고유 조합으로 간주된다. 주어진 입력에 대해 가능한 고유 숫자 조합의 개수는 150개를 넘지 않음이 보장된다. (Given an array of distinct integers candidates and a target integer target, return a .. 2021. 2. 15.