其他分享
首页 > 其他分享> > NO.26 删除有序数组的重复数字

NO.26 删除有序数组的重复数字

作者:互联网

#遍历一遍,快慢指针
class Solution:
    def removeDuplicates(self, nums: List[int]) -> int:
        pre,cur=0,1
        while cur<len(nums):       
            if nums[pre]==nums[cur]:
                nums.pop(cur)
            else:
                pre,cur=pre+1,cur+1
        return len(nums)
#思想都大差不差
class Solution:
    def removeDuplicates(self, nums: List[int]) -> int:
        fast,slow = 0,0
        while fast<len(nums):
            if nums[fast]!=nums[slow]:
                slow+=1
                nums[slow]=nums[fast]
            fast+=1
        return slow+1

 

 

标签:NO.26,cur,删除,nums,int,self,fast,数组,removeDuplicates
来源: https://www.cnblogs.com/158-174/p/16477859.html