1 line Python code with list comprehension


  • 1
    Q

    it seems working, but not as fast as other solution... ~100ms. any room to improve?

      class Solution(object):
           def removeDuplicates(self, nums):
               """
               :type nums: List[int]
               :rtype: int
               """
       
               nums[1:] = [nums[i] for i in xrange(1,len(nums)) if nums[i]!=nums[i-1]]
               return len(nums)
    

Log in to reply
 

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