This is my function
class Solution {
public:
int removeDuplicates(vector<int>& nums) {
auto i = nums.begin();
int prev = *i;
i++;
for(;i!=nums.end();i++){
if(*i == prev){
nums.erase(i);
}
prev = *i;
}
return (int)nums.size();
}
};
It is calling the vector by reference so we have to return length of the modified vector which is without duplicates.
What is wrong with it and how to improve the answer?