class Solution {
public:
  int removeDuplicates(int A[], int n) {
    // boundary case
    if (!n) return 0;

    int k = 0;
    for (int i = 1; i < n; ++i)
      if (A[i] != A[i - 1]) A[++k] = A[i];

    return k + 1;
  }
};