```
Another way
``` class Solution(object):
def removeElement(self, nums, val):
"""
:type nums: List[int]
:type val: int
:rtype: int
"""
i,j = 0, len(nums)-1
while i<=j:
if nums[i] == val:
while nums[j] == val:
j -= 1
if i > j: break
else:
nums[i] = nums[j]
j -= 1
i = i+1
nums[:] = nums[:j+1]
return len(nums)
```