public int removeElement(int[] A, int elem) {
        if(A == null || A.length == 0) return 0;
        int l = 0;
        for(int cur = 0; cur < A.length; cur++) {
            if(A[cur] != elem) {
                A[l++] = A[cur];
            }
        }
        return l;
    }