41. First Missing Positive
·
Algorithm
First Missing Positive - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 정수로 구성된 배열이 주어진다. 이 정수 배열에 존재하지 않는 가장 작은 양의 정수를 반환하는 문제다. 단 시간 복잡도는 O(N)으로 제한하고, 추가 공간은 상수 레벨까지만 허용한다. 예시 1 Input: nums = [1,2,0] Output: 3 2 Input: nums = [3,4,-1,1] Output: 2 3 Input: nums = [7,8,9,11,12] Ou..
148. Sort List
·
Algorithm
Sort List - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 단방향 연결 리스트가 주어진다. 주어진 연결 리스트를 value 값 기준으로 오름차순 정렬해 반환하는 문제다. 단 가능하다면 시간 복잡도를 O(NlogN), 추가 공간 없이 해결해보는 것이 요구사항이다. 예시 Input: head = [4,2,1,3] Output: [1,2,3,4] Input: head = [-1,5,3,4,0] Output: [-1,0,3,4,5] 풀이 1 from typin..
329. Longest Increasing Path in a Matrix
·
Algorithm
Longest Increasing Path in a Matrix - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 양의 정수로 구성된 2차원 배열이 주어진다. 2차원 배열의 임의의 인덱스 (i, j)에서 시작해 현재 인덱스가 가리키는 값 보다 큰 값으로만 4방 이동할 수 있다고 가정할 때, 이동할 수 있는 최대 거리의 길이를 반환하는 문제다. 예시 1. DFS + DP from typing import * class Solution: def longestIncr..
295. Find Median from Data Stream
·
Algorithm
Find Median from Data Stream - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 정수가 입력되고 입력된 정수는 어떤 배열에 오름차순으로 정렬되어 저장된다고 가정하자. 이때 정렬된 배열의 중간값(median)을 반환하는 문제다. 예시 Input ["MedianFinder", "addNum", "addNum", "findMedian", "addNum", "findMedian"] [[], [1], [2], [], [3], []] Output [n..
42. Trapping Rain Water
·
Algorithm
Trapping Rain Water - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 0보다 같거나 큰 양의 정수로 이루어진 배열이 주어진다. 주어진 배열을 이용해 해당 index에 value 길이의 벽을 세운다고 가정하고 비가 올 때 최대로 받을 수 있는 빗물의 양을 구하는 문제다. 1. Stack from typing import * class Solution: def trap(self, heights: List[int]) -> int: stack, answ..
56. Merge Intervals
·
Algorithm
Merge Intervals - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 양의 정수 2개로 이루어진 배열이 담긴 배열이 주어진다. 각 양의 정수는 시작과 끝을 의미하고 이 배열 하나를 interval로 한다. 만일 interval 간의 끝과 시작이 같거나 겹친다면 하나의 interval로 만들 수 있을 때 interval 들을 합친 결과를 반환하는 문제다. 예시 Input: intervals = [[1,3],[2,6],[8,10],[15,18]] Outpu..