Python, two pointers, simple.


  • 1
    N
            i = 1
            for j in range(len(nums)):
                if nums[i-1] != nums[j]:
                    nums[i], nums[j] = nums[j], nums[i]
                    i += 1
            return len(nums[:i])
    

Log in to reply
 

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