先统计一下val出现的次数,然后再将它们一个一个的删除 class Solution(object): def removeElement(self, nums, val): """ :type nums: List[int] :type val: int :rtype: int """ n = nums.count(val) while n: if val in nums: nums.remove(val) n -= 1 return len(nums)