class Solution {
public:
int removeDuplicates(int A[], int n) {
if (n == 0)
{
return n;
}
int k = 0;
for (int i = 1; i < n; i++)
{
if (A[i] != A[k])
{
A[++k] = A[i];
}
}
return k + 1;
}
};
My onepass solution

Thanks for your post. However it would be better to share solution with correct code format and elaborated thoughts. Please read the Discuss FAQ for more info. Take a look at good sharing example

The method is:

Check if the length is 0, if it is, then return 0.

Initialize the a counter, say k to be 0.

Go from 1 in a for loop:
(Note that k should be 1 less than i for comparison) if element at k is different from at i, then update k by 1, and set element at k+1 be A[i]
 do nothing else

As our counter is at first 1 less than the really length, we return counter + 1.
