LinkSearchMenuExpandDocument

26. Remove Duplicates from Sorted Array

Solution Code

Python

classSolution:defremoveDuplicates(self,nums:List[int])->int:# go through the array, # if nth item and (n+1)th item match, pop nth item, but don't forward # otherwise go forward i=1whilei<len(nums):ifnums[i-1]==nums[i]:nums.pop(i-1)else:i+=1returnlen(nums)

© 2023. All rights reserved.

close