Single Number
2015-07-21 17:05
239 查看
描述
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?
异或,不仅能处理两次的情况,只要出现偶数次,都可以清零。
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?
异或,不仅能处理两次的情况,只要出现偶数次,都可以清零。
class Solution { public: int singleNumber(vector<int>& nums) { int x = 0; for (size_t i = 0; i < nums.size(); ++i) x ^= nums[i]; return x; } };
相关文章推荐
- 二叉搜素树 二叉排序树 插入 删除 中序输出
- PC-启动慢的解决好方法!
- fancybox 基础 简单demo
- java面试常见问题之Hibernate总结
- mediawiki上传文件大小的设置
- Java 死锁的简单实例
- Android SDK 和 Eclipse ADT 离线安装 教程
- Linux自学笔记:02_vi编辑器的简单使用
- POJ Treasure Exploration 2594【Warshall求传递闭包+最小路径覆盖】
- [Python学习] 简单爬取CSDN下载资源信息
- IE-一根网线二台电脑上网
- mvc与三层结构终极区别
- Algorithms—2.Add Two Numbers
- Android Touch事件分发机制
- Delphi Edit限制只能输入数字
- 设计模式-抽象工厂(Abstract Factory)
- 视频和字幕同步的实现(java版)
- zedboard中OLED源代码
- Github个人使用经历
- SVN数据转移