반응형 분류 전체보기128 [DSA][Two Pointers] 05. Trapping Rain Water LeetCode 42 05. Trapping Rain WaterGiven 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. [질문하기]- 양 끝은 bound 되지 않았다고 가정하나요? YES- 모든 height 값은 양의 정수인가요, 0도 포함되나요? 0을 포함한 자연수 값이 가능하다. [아이디어]- 각 인덱스에 대해 왼쪽과 오른쪽에서의 max bar의 높이를 구하자. [풀이 1] Prefix & Suffix Arraysclass Solution: def trap(self, height: List[in.. 2025. 6. 6. [DSA][Two Pointers] 04. Container With Most Water LeetCode 11 04. Container With Most WaterYou are given an integer array height of length n.There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]).Find two lines that together with the x-axis form a container, such that the container contains the most water.Return the maximum amount of water a container can store.Notice that you may not slant th.. 2025. 6. 5. [DSA][Two Pointers] 03. 3Sum LeetCode 15 03. 3SumGiven an integer array nums, return all the triplets [nums[i], nums[j], nums[k]]such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.Notice that the solution set must not contain duplicate triplets. [질문하기]- 정해진 출력 순서가 있나요? NO- 항상 valid 한 정답이 있나요? 없다면 []를 return 하면 될까요? [아이디어]- Two Sum에서 사용했던 Hash/Two Pointer 방식을 확장하자. [풀이 1] Hash Mapclass Solution: .. 2025. 6. 4. [DSA][Two Pointers] 02. Two Sum II - Input Array Is Sorted LeetCode 167 02. Two Sum II - Input Array Is SortedGiven a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number.Let these two numbers be numbers[index1] and numbers[index2] where 1 [질문하기]- 정수 배열에 중복된 숫자가 있을 수 있나요? NO- 정답은 단 하나라고 가정해도 될까요? or 항상 valid 한 정답이 있나요? YES [아이디어]- Two Pointer를 사용하여 Sum과 .. 2025. 6. 3. 이전 1 ··· 17 18 19 20 21 22 23 ··· 32 다음