Simple Python Solution, O(n) time and O(1) space


  • 0
    N
    class Solution(object):
        def removeDuplicates(self, nums):
            ctr = 0
            for i in xrange(len(nums)):
                if nums[i] != nums[i - 1] and i > 0 or i == 0:
                    nums[ctr] = nums[i]
                    ctr += 1
            return ctr
    

Log in to reply
 

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