leetcode

Single Number

Given an array of integers, every element appears twice except for one. Find that single one.

e.g: [2,2,2,2,1] -> 2 ^ 2 ^ 2 ^ 2 ^ 1 = 1

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