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);
    }
};

水一发

posted @ 2014-03-26 00:09  卖程序的小歪  阅读(90)  评论(0编辑  收藏  举报