public int removeElement(int[] A, int elem) {
        int i=0, j = A.length - 1;
        while(i <= j)
        {
            if(A[i] == elem && A[j] != elem)
            {
                A[i] ^= A[j];
                A[j] ^= A[i];
                A[i] ^= A[j];
                i++;
                j--;
                continue;
            }
            else if(A[j] == elem)
            {
                j--;
                continue;
            }
            i++;
        }
        return j + 1;
    }