Scribbling

LeetCode: 26. Remove Duplicates from Sorted Array 본문

Computer Science/Coding Test

LeetCode: 26. Remove Duplicates from Sorted Array

focalpoint 2021. 8. 27. 18:19

 

class Solution:
    def removeDuplicates(self, nums: List[int]) -> int:
        prev = None
        i = 0
        for num in nums:
            if num != prev:
                nums[i] = num
                prev = num
                i += 1
        return i