Leetcode/python/remove_element.py
2024-03-08 17:14:04 +00:00

9 lines
237 B
Python

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