Notice
Recent Posts
Recent Comments
Link
«   2026/01   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags more
Archives
Today
Total
관리 메뉴

eumjo_o

leetcode0026 - Remove Duplicates from Sorted Array / Easy / TypeScript 본문

카테고리 없음

leetcode0026 - Remove Duplicates from Sorted Array / Easy / TypeScript

eumjo_o 2023. 4. 30. 23:32

https://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;
};