| 4 | //then return the count of remaining elements |
| 5 | |
| 6 | class Solution { |
| 7 | public: |
| 8 | int removeElement(vector<int>& nums, int val) { |
| 9 | int c=0;//initialize the count to be 0 |
| 10 | for (auto i = nums.begin(); i != nums.end(); ++i) { //traversing the nums vector |
| 11 | if (*i == val) { |
| 12 | nums.erase(i); //if the iterator points to the value to be removed then we delete it |
| 13 | i--; //decrement the iterator by 1 |
| 14 | } |
| 15 | else c++;//increment the count by 1 |
| 16 | } |
| 17 | return c; //here we return the count of remaining elements |
| 18 | } |
| 19 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected