Simple Python Solution using 2 pointers


  • 0
    Y
    class Solution(object):
        def removeDuplicates(self, nums):
            if nums == []: return 0
            i = 0
            for index,value in enumerate(nums):
                if value > nums[i]:
                    i+=1
                    nums[i],nums[index] = nums[index],nums[i]
            return i + 1

Log in to reply
 

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