27 Remove Element
使用单指针,循环判断当前数组元素是否和指定value相等,如果相等,则弹出当前元素。
class Solution:
def removeElement(self, nums, val):
"""
:type nums: List[int]
:type val: int
:rtype: int
"""
point = 0
index = 0
ans = 0
for i in range(len(nums)):
point = nums[index]
if point == val:
nums.pop(index)
nums.append(val)
else:
index += 1
ans += 1
return ans