欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

LintCode Python 101. 删除排序数组中的重复数字 II

程序员文章站 2022-06-11 16:13:43
...
def removeDuplicates(self, nums):
    # write your code here
    if nums == []:
        return 0
    index,count = 0, 1
    for i in range(1, len(nums)):
        if nums[index] == nums[i] and count < 2:
            index += 1
            count += 1
            nums[index] = nums[i]
        if nums[index] != nums[i]:
            index += 1
            count = 1
            nums[index] = nums[i]
    return index+1