题解 思想 思路挺简单的,主要利用两个变量,a来遍历,b用来存我们expect的数字的序列,和删除有序数组的重复项有点像 代码 class Solution(object): def removeElement(self, nums, val): """ :type nums: List[int] :type val: int :rtype: int """ a = 0 b = 0 while a<len(nums): if nums[a]!=val: nums[b]=nums[a] b = b+1 a =a + 1 return b