1 class Solution {
2 public:
3 int removeElement(vector<int>& nums, int val) {
4 int count = 0;
5 vector<int> ans;
6 for (int i = 0; i < nums.size(); i++){
7 if (nums[i] != val)
8 {
9 ans.push_back(nums[i]);
10 count++;
11 }
12 }
13 ans.resize(count);
14 nums = ans;
15 return count;
16 }
17 };