Day04--删除排序数组中的重复项 II(Python实现)


Day04--删除排序数组中的重复项 II(Python实现)

class Solution:
    def removeDuplicates(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        if len(nums) == 0:
            return 0
        
        count = 1
        j = 0
        for i in range(1, len(nums)):
            if nums[i] != nums[j]:
                j += 1
                nums[j] = nums[i]
                count = 1
            else:
                if count >= 2:
                    continue
                else:
                    j += 1
                    nums[j] = nums[i]
                    count += 1
        del nums[j+1:len(nums)]
        return len(nums)


上一篇:python解析json


下一篇:Python解析JSON详解