leetcode 26 Remove Duplicates from Sorted Array

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;
    }
};
posted @ 2017-02-11 23:57  王坤1993  阅读(91)  评论(0编辑  收藏  举报