与上一题“Remove Duplicates from Sorted Array”类似。
class Solution {
public:
int removeElement(int A[], int n, int elem) {
// Note: The Solution object is instantiated only once and is reused by each test case.
if(n == 0) return n;
int index = 0;
for(int i = 0; i < n; i++){
if(elem == A[i]){
continue;
}
A[index++] = A[i];
}
return index;
}
};