26.删除有序数组中的重复项

Python里原地删除还是容易的

class Solution:
    def removeDuplicates(self, nums: List[int]) -> int:
        i = 0
        while i < len(nums) - 1:
            if nums[i] == nums[i+1]:
                del nums[i]
                continue
            else:
                i += 1
        return len(nums) 

评论