Day.5 Single Number(136)
2017-11-07 本文已影响0人
前端伊始
问题描述
Given an array of integers, every element appears twice except for one. Find that single one.
思路:利用0和任何数异或都为该数定理
/**
* @param {number[]} nums
* @return {number}
*/
var singleNumber = function(nums) {
sum=0;
for(var i=0;i<nums.length;i++){
sum^=nums[i];
}
return sum;
};
文末彩蛋
Day.5 Single Number(136)