EZ Python Solution


  • 0
    class Solution(object):
        def removeDuplicates(self, nums):
            writer, idx = 0, 0
            while idx < len(nums):
                if idx == 0 or nums[idx] != nums[idx - 1]:
                    nums[writer] = nums[idx]
                    writer += 1
                elif idx == len(nums) - 1 or nums[idx] != nums[idx + 1]:
                    nums[writer] = nums[idx]
                    writer += 1
                idx += 1
            return writer
    

Log in to reply
 

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