标签:tps rem not modifying duplicate modify ica you use
Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.
Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
My idea:use 1 pointer to search
class Solution: def removeDuplicates(self, nums): if(nums==[]): return 0 a=nums[0] p=0 while(p<len(nums)-1): while((nums[p+1]==a)): del nums[p+1] if(p+1==len(nums)): break p=p+1 if (p == len(nums)): break a = nums[p] return len(nums)
思路跟前面几题差不多其实
26. Remove Duplicates from Sorted Array
标签:tps rem not modifying duplicate modify ica you use
原文地址:https://www.cnblogs.com/dmndxld/p/10851788.html