Single Number
2015-08-28 22:17
162 查看
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?
Solution:
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
Solution:
class Solution { public: int singleNumber(vector<int>& nums) { if(nums.size() == 0) return 0; for(int i = 1; i < nums.size(); ++i) nums[0] ^= nums[i]; return nums[0]; } };
相关文章推荐
- 非参数密度估计(直方图与核密度估计)
- android---gettag()与settag()的妙用
- Linux的timerfd分析
- 字符集和字符编码(Charset & Encoding)
- 树莓派deian的linux常用命令
- 深入浅出CChart 每日一课——快乐高四第十一课 不离不弃,利用CChartWnd实现多区域绘图
- ehcache memcache redis 三大缓存男高音
- 单表60亿记录等大数据场景的MySQL优化和运维之道
- HTTP文件传输
- SSH之旅(一)——框架简介
- Linux 基础命令
- oracle 导入execl
- easyui-editing datagrid 批量保存数据 二
- win8 X64上安装32位Oracle Instant Client(即时客户端) 安装与配置
- android头像设置功能
- 2015应该学习的前端语言与框架
- session共享
- 数据结构之---C语言实现斐波那契查找
- linq to sql 增删改查
- 经验分享:如何构建亿级前端读服务