您的位置:首页 > 其它

lintcode--l落单的数

2017-08-09 16:32 267 查看
给出2*n + 1 个的数字,除其中一个数字之外其他每个数字均出现两次,找到这个数字。

您在真实的面试中是否遇到过这个题? 

Yes

样例

给出 [1,2,2,1,3,4,3],返回 4

public class Solution {

    public static int singleNumber(int[] arr){
int res =0;
for(int i =0;i<arr.length;i++){
res = res ^ arr[i];
}
return res;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: