eumjo_o
leetcode0026 - Remove Duplicates from Sorted Array / Easy / TypeScript 본문
카테고리 없음
leetcode0026 - Remove Duplicates from Sorted Array / Easy / TypeScript
eumjo_o 2023. 4. 30. 23:32https://leetcode.com/problems/remove-duplicates-from-sorted-array/
Time Complexity O(N)
- new Set(array) : O(N)
- array 순회 모두 : O(N)
Space Complexity O(N)
- 중복을 제거한 숫자 배열은 최대 길이가 N이기 때문에 O(N)
function removeDuplicates(nums: number[]): number {
const sortedArray = [...new Set(nums)];
for(let i = 0; i < sortedArray.length; i++) {
nums[i] = sortedArray[i];
};
return sortedArray.length;
};