4.20
public class Solution {
/**
*@param A: A list of integers
*@param elem: An integer
*@return: The new length after remove
*/
public int removeElement(int[] A, int elem) {
// write your code here
int low = 0;
int height = A.length-1;
while(low < height){
while(low < height && A[low] != elem){
low ++;
}
while(low < height && A[height] == elem){
height --;
}
if(A[low] == elem){
A[low] = A[height];
height--;
}
}
return height+1;
}
}