본문 바로가기

IT/코딩테스트

[Leetcode] 26. Remove Duplicates from Sorted Array

728x90

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

class Solution:
    def removeDuplicates(self, nums: List[int]) -> int:

        count = len(nums)

        before = nums[0]
        for i in range(1, len(nums)):
            if before == nums[i]:
                nums[i] = 101
                count -= 1
            else:
                before = nums[i]
        
        nums.sort()
        return count

 

728x90