remove element

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 sum = 0;
        for( int i = 0; i<A.length;i++){
            if(A[i] != elem){
                A[sum] = A[i];
                sum ++;
            }
        }
        return sum;
    }
}
原文地址:https://www.cnblogs.com/heylinart/p/7651298.html