Easy, Readable and Efficient C++,


#1

Before telling me that I had to do it in Constant space, let me tell you vector<bool> takes only one bit. cheers!!

int Solution::removeDuplicates(vector<int> &A) { vector<bool> checker (A.size(), 0); int p = INT_MIN; for(int i=0;i<A.size();i++){ if(A[i] != p){ checker[i] = 1; p = A[i]; if(A[i+1] == A[i] and i+1<A.size()) checker[i+1] = 1; } } int size=0; for(int i =0;i<A.size();i++){ if(checker[i] ==1){ A[size] = A[i]; size++; } } return size; }