[LeetCode] Remove Element (Python)

2024. 2. 27. 11:03자료구조

 

 

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