LeetCodeDiary

A Diary for solving LeetCode problems

View on GitHub
class Solution:
    def removeDuplicates(self, nums: List[int]) -> int:
        j = 1
        for i in range(1, len(nums)):
            if nums[i] != nums[j - 1]:
                nums[j] = nums[i]
                j += 1
        return j

数组 简单 0080.删除有序数组中的重复项II 的简化版

代码一致,双指针法

https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/