MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / Solution

Class Solution

LeetCode_problems/Remove Element/solution.cpp:6–19  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4//then return the count of remaining elements
5
6class Solution {
7public:
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};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected