Do it like quicksort.

Use a left pointer to track the last element found that is equal to val (scanned from the left) and right to track the last element that is not equal to val. Then swap left/right

```
class Solution {
public:
int removeElement(vector<int>& nums, int val) {
int left= 0, right=nums.size()-1;
while(left<=right)
{
if(nums[left] != val) ++left;
else if(nums[right] == val) --right;
else swap(nums[left++], nums[right--]);
}
return left;
}
};
```