```
class Solution(object):
def removeElement(self, nums, val):
"""
:type nums: List[int]
:type val: int
:rtype: int
"""
i = 0
while i < len(nums):
if nums[i] == val:
tmp = nums.pop()
if i == len(nums):
return i
nums[i] = tmp
else:
i += 1
return i
```