Skip to content

Latest commit

 

History

History
21 lines (15 loc) · 759 Bytes

File metadata and controls

21 lines (15 loc) · 759 Bytes

Remove Duplicates from Sorted Array

Problem can be found in here!

def removeDuplicates(nums: List[int]) -> int:
    slow, fast = 0, 1
    while fast < len(nums):
        if nums[fast] != nums[slow]:
            slow += 1
            nums[slow] = nums[fast]
        fast += 1

    return slow + 1

Explanation: We use a fast pointer to find the next unique value. Then, we switch the value between slow+1 and fast.

Time Complexity: O(n), Space Complexity: O(1)