LeetCode Remove Element

class Solution {
public:
    int removeElement(int A[], int n, int elem) {
        if (A == NULL || n < 1) return 0;
        int rpos = 0, wpos = 0;
        int removed = 0;
        while (rpos < n) {
            if (A[rpos] == elem) {
                rpos++;
                removed++;
            } else {
                A[wpos++] = A[rpos++];
            }
        }
        return n - removed;
    }
};

再水

原文地址:https://www.cnblogs.com/lailailai/p/3806063.html