問題描述
Given an array of integers, every element appears twice except for one. Find that single one.
思路:利用0和任何數(shù)異或都為該數(shù)定理
/**
* @param {number[]} nums
* @return {number}
*/
var singleNumber = function(nums) {
sum=0;
for(var i=0;i<nums.length;i++){
sum^=nums[i];
}
return sum;
};
文末彩蛋