Algorithms—136.Single Number
2015-06-26 15:10
537 查看
思路:异或计算。0^a=a;a^b=b^a。
public class Solution {
public int singleNumber(int[] nums) {
int answer=0;
for (int i = 0; i < nums.length; i++) {
answer^=nums[i];
}
return answer;
}
}
public class Solution {
public int singleNumber(int[] nums) {
int answer=0;
for (int i = 0; i < nums.length; i++) {
answer^=nums[i];
}
return answer;
}
}
相关文章推荐
- msvc2010生成的指令序列有问题,可能跟pgo有关
- Algorithms—134.Gas Station
- MeteoInfoLab脚本示例:inpolygon
- 韩团god朴俊亨迎娶小13岁空姐 成员唱祝歌
- Algorithms—125.Valid Palindrome
- Algorithm --> 二进制中1的个数
- Google Guava官方教程(中文版)
- Algorithms—119.Pascal's Triangle II
- Go语言用堆排序的方法进行一千万个int随机数排序.
- Algorithms—118.Pascal's Triangle
- VIEWGOOD(远古)企业培训考核提升系统解决方案
- poj 1179 Polygon
- Django 后台表单标签的自定义
- Django model字段类型清单
- Django模块笔记【一】
- 求LR(0)文法的规范族集和ACTION表、GOTO表的构造算法
- 北大百炼1003 Hangover 题解
- TEA -- Tiny Encryption Algorithm
- Algorithm --> n位数去掉k位后找最小数
- Algorithm --> 顺序打印矩阵