找出数组中不重复的数

 @Test
    public void test() {
        int[] a = {1, 2, 3, 2, 1, 3, 4, 4, 6};
        System.out.println(singleNumber(a));


    }
    public int singleNumber(int[] A) {
        if(A == null || A.length == 0) {
            return -1;
        }
        int rst = 0;
        for (int i = 0; i < A.length; i++) {
            rst ^= A[i];
        }
        return rst;
    }

 

posted @ 2020-01-10 17:41  暖暖-木木  阅读(1272)  评论(0编辑  收藏  举报