leetcode 136 —— Single Number
2015-08-14 10:24
423 查看
Given an array of integers, every element appears twice except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
思路 A^B^A=B
class Solution {
public:
int singleNumber(vector<int>& nums) {
int res=nums[0];
for (int i = 1; i < nums.size(); i++)
res ^= nums[i];
return res;
}
};
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
思路 A^B^A=B
class Solution {
public:
int singleNumber(vector<int>& nums) {
int res=nums[0];
for (int i = 1; i < nums.size(); i++)
res ^= nums[i];
return res;
}
};
相关文章推荐
- 把word文档转成pdf格式查看怎么做
- libnet--arp/arp应答
- hdoj 1285 确定比赛名次 【拓扑排序】
- [Spring Boot Debug]在 intellij idea 中无法编译 javad代码 -source 1.6 中不支持 diamond 运算符
- Yubikey不再记忆密码
- WPAD 的原理及实现
- 7月“.中国”域名总量跌至26.3万个 颓势减缓逆袭有望
- C#中的装箱与拆箱
- jedis read time out
- 关于Unity3D中的空引用 Null Reference Exception
- 年薪10万、30万、50万的PM分别该具有什么样的素质?
- linbet————udp实例
- ubuntu下opencv的配置和第一个opencv的运行
- PHP SYSTEM WARNING: 'date_default_timezone_get()'
- HDU 1075 What Are You Talking About(字典树模板题)
- POJ1006: 中国剩余定理的完美演绎(转)
- .net 命名管道(NamedPipe) 的使用
- android开发(12) 使用无线网络和切换到GPRS连接
- arcgis for android 学习 - (1) 安装环境简述
- arcgis for android 学习 - (2) hello Wrold. 显示一个地图