← switch

80. Remove Duplicates from Sorted Array II

medium

Array · Two Pointers

read the problem on leetcode →

first solved 13 Aug 2024 · 2 accepted submissions

python
class Solution:
    def removeDuplicates(self, nums: List[int]) -> int:
        k=0
        for n in nums:
            if k<2 or n!=nums[k-2]:
                nums[k]=n
                k+=1
        return k
            
                

        
python
class Solution:
    def removeDuplicates(self, nums: List[int]) -> int:
        i=0
        for k in nums:

            if i<2 or k!=nums[i-2]:
                nums[i]=k
                i+=1
        return i