I am searching for a long time on net. But no use. Please help or try to give some ideas how to solve this problem.
class Solution{
public:
int removeElement(vector<int> &nums, int val)
{
for (auto &it = nums.begin(); it != nums.end(); ++it)
{
if (*it == val)
{
it = nums.erase(it);
}
}
return nums.size();
}
};
int main(void)
{
Solution s;
vector<int> vi = { 3, 2, 2, 3 };
cout << "size = " << s.removeElement(vi, 3) << endl;
for (auto &i : vi)
{
cout << i << " ";
}
cout << endl;
return 0;
}
which are the class body and main function body of my code. But when i run it, compiler popped a window: