class Solution {
public:
int removeDuplicates(int A[], int n) {
if(n < 2) return n;
int id = 1;
for(int i = 1; i < n; ++i)
if(A[i] != A[i1]) A[id++] = A[i];
return id;
}
};
My Solution : Time O(n), Space O(1)

OP's idea is similar to this problem
https://oj.leetcode.com/problems/removeelement/
the only difference is comparing two adjacent elements in array rather than given element.