Remove Element
Total Accepted: 7901 Total Submissions: 24070Given 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.
The tricky part is unless check discussion, you don't know what the question really means
public class Solution {
public int removeElement(int[] A, int elem) {
int len = A.length;
if (A==null){
return 0;
}
int i = 0;
int count = 0;
while(i<len){
if(A[i] == elem){
i++;
count++;
}
else{
A[i-count] = A[i];
i++;
}
}
return A.length-count;
}
}