[Problem]
[Solution]
Given an array and a value, remove all instances of that value in place and return the new length.
The order of elements can be changed. It doesn't matter what you leave beyond the new length.
[Solution]
class Solution {说明:版权所有,转载请注明出处。 Coder007的博客
public:
int removeElement(int A[], int n, int elem) {
// Note: The Solution object is instantiated only once and is reused by each test case.
int i = 0, j = 0;
while(j < n){
if(A[j] != elem){
A[i++] = A[j];
}
j++;
}
return i;
}
};