leetcode 26 Remove Duplicates from Sorted Array

2018-06-04 12:35:28 浏览数 (4)

代码语言:javascript复制
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;
    }
};

1 人点赞