LeetCode-26(删除排序数组中的重复项)(Python)

image.png
解法一(84 ms 52.79%):
class Solution(object):
    def removeDuplicates(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        if len(nums)==0:
            return 0
        if len(nums)==1:
            return 1
        k=0
        for i in range(len(nums)-1):
            if nums[i]!=nums[i+1]:
                nums[k+1]=nums[i+1]
                k+=1
        del nums[k+1:]
        return len(nums)

你可能感兴趣的:(LeetCode-26(删除排序数组中的重复项)(Python))