算法题 落单的数

描述

给出2*n + 1 个的数字,除其中一个数字之外其他每个数字均出现两次,找到这个数字。

样例

给出 [1,2,2,1,3,4,3],返回 4

public class Solution {
    /**
     * @param A: An integer array
     * @return: An integer
     */
    public int singleNumber(int[] A) {
        // write your code here
        if(A==null || A.length==0){
            return -1;
        }
        int rst =0;
        for(int i: A){
            rst^=i;
        }
        
        return rst;
        
    }
}

猜你喜欢

转载自www.cnblogs.com/yueguangmoliya/p/9015089.html