LeetCode Remove Duplicates from Sorted Array
class Solution { public: int removeDuplicates(int A[], int n) { if (n == 0) return 0; int *rpos = A, *wpos = A + 1, *end = A + n; int cur; int pre = *(rpos++); while (rpos != end) { cur = *(rpos++); if (pre == cur) continue; *(wpos++) = pre = cur; } return n - (rpos - wpos); } };
水一发