A/C Python solution, easy to understand, beat 0.14%


  • 0
    W
    def removeDuplicates(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        lenNums = len(nums)
        print "lenNums = ", lenNums
    
        tail = 0
        duplicate = 0
    
        if lenNums <= 2:
            return lenNums
    
        for i in range(1, lenNums):
            print "i = ", i, " nums[i] = ", nums[i]
    
            if nums[i] <= nums[tail]:
                duplicate += 1
    
                if duplicate > 1:
                    continue
            else:
                duplicate = 0
    
            tail += 1
            nums[tail] = nums[i]
    
        #print "end nums = ", nums
        #print "end tail+1 = ", tail+1
    
        return tail+1

Log in to reply
 

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