class Solution:
def removeElement(self, nums: List[int], val: int) -> int:
j=0
for i in range(len(nums)):
if nums[i]!=val:
nums[j]=nums[i]
j+=1
return j if nums else 0
类似上一道题,都是将不等于val的值重新赋值