class Solution: def removeElement(self, nums: List[int], val: int) -> int: while val in nums: nums.remove(val) return len(nums)
remove()方法在使用过程中,往往需要结合while循环,来移除List中所有满足要求的值