和上一题类似,没有太大难度。
public class Solution {
public int removeElement(int[] A, int elem) {
if (A == null || A.length == 0) {
return 0;
}
int count = 0;
for (int next = 0; next < A.length ;++next) {
if (A[next] != elem) {
A[count++] = A[next];
}
}
return count;
}
}