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


  • 0
    W

    class Solution(object):
    def removeDuplicates(self, nums):
    """
    :type nums: List[int]
    :rtype: int
    """
    # print "nums = ", nums

        lenNums = len(nums)
    
        if lenNums == 0:
            return
        elif lenNums == 1:
            return 1
    
        #print "lenNums = ", lenNums
    
        tail = 0
        for i in range(1, lenNums):
            #print "i = ", i, " nums[i] = ", nums[i]
    
            if nums[i] <= nums[tail]:
                #print "found duplicate"
                continue
    
            else:
                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.