Skip to content

Latest commit

 

History

History
18 lines (16 loc) · 398 Bytes

026.md

File metadata and controls

18 lines (16 loc) · 398 Bytes

26. Remove Duplicates from Sorted Array

Solution 1 (O(n))

class Solution(object):
    def removeDuplicates(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        idx = 0
        for num in nums:
            if idx < 1 or num != nums[idx - 1]:
                nums[idx] = num
                idx += 1
        return idx