LeetCode 26. Remove Duplicates from Sorted Array

Seohyun·2024년 11월 25일
0

알고리즘

목록 보기
35/36
class Solution:
    def removeDuplicates(self, nums: List[int]) -> int:
        check = []
        for i in range(len(nums)):
            if nums[i] not in check:
                check.append(nums[i])
        for i in range(len(check)):
            nums[i] = check[i]
        return len(check)

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

난 항상 문제를 어렵게 생각하는 것 같다...

profile
Hail hamster

0개의 댓글