```
int removeElement(vector<int>& nums, int val) {
int length = nums.size();
int idx = 0;
if(length < 1)
return length;
for(;;)
{
if(nums[idx] == val)
{
nums[idx] = nums[length-1];
length--;
}
else
{
idx++;
}
if(idx > length-1)
break;
}
return length;
}
```