Link Search Menu Expand Document

26. Remove Duplicates from Sorted Array

Solution Code

Python

class Solution:
    def removeDuplicates(self, nums: List[int]) -> int:
        # go through the array,
        # if nth item and (n+1)th item match, pop nth item, but don't forward
        # otherwise go forward

        i = 1
        
        while i < len(nums):
            if nums[i - 1] == nums[i]:
                nums.pop(i - 1)
            else:
                i += 1

        return len(nums)

© 2023. All rights reserved.

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy