given a non-empty array of integers, each element appears twice except for an element that appears only once. Find the element that only appears once.
example 1:
: [2,2,1]
: 1
example 2:
: [4,1,2,1,2]
: 4
the answer with the highest running efficiency
var singleNumber = function(nums) {
return nums.reduce((acc, num) => acc^num, 0)
};
I don"t understand why a ^ can calculate the value. Can you explain the operation?