Oh come on. We’ve done this before.
class Solution {
public:
int removeElement(vector<int>& nums, int val) {
auto new_end = std::remove(std::begin(nums), std::end(nums), val);
return std::distance(std::begin(nums), new_end);
}
};