【leetcode❤python】26. Remove Duplicates from Sorted Array

时间:2024-01-20 22:01:03

#-*- coding: UTF-8 -*-
class Solution(object):
    def removeDuplicates(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        if len(nums)<=1:return len(nums)
        pre=0;next=1
        while True:
            if nums[next]==nums[pre]:
                del nums[next]
            else:
                pre=next
                next+=1
            if next>=len(nums):break
            
        return len(nums)    
        
#        sorted(set(nums),key=nums.index)
#        print nums
sol=Solution()
print sol.removeDuplicates([1,1,2,2,4,4,5,5])