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

#-*- 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])

上一篇:RouterOS 软路由开启SSH服务器


下一篇:C# WinForm多线程(一)----- Thread类库