Python | Leetcode Python题解之第80题删除有序数组中的重复项II-题解:

class Solution:
    def removeDuplicates(self, nums: List[int]) -> int:
        idx, left, right = 0, 0, 0
        while left < len(nums):
            nums[idx] = nums[left]
            idx += 1
            while right < len(nums) and nums[right] == nums[left]:
                right += 1
            if right - left > 1:
                nums[idx] = nums[left]
                idx += 1
            left = right
        return idx
上一篇:K8S面试题学习4


下一篇:【STM32+HAL】微秒级延时函数汇总