7 lines solution


  • 0
    S
    def removeDuplicates(self, nums):
            if len(nums)<3: return len(nums)
            cur = 2
            for i in range(2,len(nums)):
                if nums[cur-1]!=nums[i] or nums[cur-2]!=nums[cur-1]==nums[i]:
                    nums[cur] = nums[i]
                    cur += 1
            return cur

Log in to reply
 

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