[LeetCode] Sort Colors
목차 문제 공간복잡도를 O(1)로 정렬하는 문제입니다. 0,1,2 으로 구성된 array가 있을 때 정렬하는 문제입니다. 대부분의 정렬 예시 Input: nums = [2,0,2,1,1,0] Output: [0,0,1,1,2,2] Input: nums = [2,0,1] Output: [0,1,2] 제약사항 n == nums.length 1
2024. 4. 16.
[LeetCode] Rotate Array
목차 문제 주어진 배열을 k만큼 rotate 시키는 문제입니다. (단, 추가적인 공간을 생성하지 않고 문제를 해결해야 합니다.) 예시 Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 steps to the right: [7,1,2,3,4,5,6] rotate 2 steps to the right: [6,7,1,2,3,4,5] rotate 3 steps to the right: [5,6,7,1,2,3,4] Input: nums = [-1,-100,3,99], k = 2 Output: [3,99,-1,-100] Explanation: rotate 1 steps to the right: [99,-1,-100,3..
2024. 4. 15.
[LeetCode] Minimum Size Subarray Sum
목차 문제 연속된 배열에서 특정 구간의 합이 target보다 커지는 구간 중 구간 길이가 최소인 길이를 구하는 문제입니다. 예시 Input: target = 7, nums = [2,3,1,2,4,3] Output: 2 Explanation: The subarray [4,3] has the minimal length under the problem constraint. Input: target = 4, nums = [1,4,4] Output: 1 Input: target = 11, nums = [1,1,1,1,1,1,1,1] Output: 0 문제 풀이 풀이 1 : 완전탐색 풀이 단순하게 모든 i~j 까지에 대해서 Sum을 계산하는 방식입니다. i, j ,sum함수 -> n^3의 시간복잡도를 가집니다. 코..
2024. 4. 10.