Day.5 Single Number(136)

问题描述
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;
};
    原文作者:前端伊始
    原文地址: https://www.jianshu.com/p/0ab2b3e90069
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞