Skip to content

Latest commit

 

History

History

80-RemoveDuplicatesfromSortedArrayII

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Remove Duplicates from Sorted Array II

Problem can be found in here!

def removeDuplicates(nums: List[int]) -> int:
    if len(nums) < 3:
        return len(nums)

    slow = fast = 2
    while fast <= len(nums)-1:
        if nums[fast] != nums[slow-2]:
            nums[slow] = nums[fast]
            slow += 1
        fast += 1
    
    return slow

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