My accepted python solution


  • 0
    S
    def removeDuplicates(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        if len(nums) < 3:
            return len(nums)
        p1, p2 = 0, 2
        l = len(nums)
        while p2 < l:
            while nums[p2] == nums[p1]:
                nums.pop(p2)
                l -= 1
                if p2 == l:
                    break
            p1 += 1
            p2 = p1 + 2
        return len(nums)
    

    My code will modify the nums, by removing all duplicates that are more than twice.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.