My 80ms python code


  • 0
    S
    class Solution(object):
        def removeDuplicates(self, nums):
            if nums == []: return 0
            left = 0
            for i in range(1,len(nums)):
                if nums[i] != nums[left]:
                    if left + 1 < i:
                        nums[left+1] = nums[i]
                    left += 1
            del nums[left+1:]
            return len(nums)
    

    Look forward to suggestions to remove more duplicated steps. Thanks.


Log in to reply
 

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