首页 > 代码库 > [Leetcode] 27 - Remove Element

[Leetcode] 27 - Remove Element

原题链接:https://oj.leetcode.com/problems/remove-element/


很简单一道题。。。

class Solution {
public:
    int removeElement(int A[], int n, int elem) {
        int front = 0;
        int idx = 0;
        while (idx < n) {
            if (A[idx] != elem) {
                A[front] = A[idx];
                ++front;
            }
            ++idx;
        }
        
        return front;
    }
};


[Leetcode] 27 - Remove Element