class Solution { public: int removeDuplicates(int A[], int n) { if (n <= 1) return n; int pre = 0, cur = 0; while (cur < n) { if (A[cur] == A[pre]) ++cur; else A[++pre] = A[cur++]; } return pre + 1; } };