Leetcode/python/27_remove_element.py

9 lines
237 B
Python
Raw Permalink Normal View History

2024-03-08 17:14:04 +00:00
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