[leetcode] Single Number
2015-06-08 10:01
127 查看
From : https://leetcode.com/problems/single-number/
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) { if(nums.size() == 0) return 0; int result = nums[0], len=nums.size(); for(int i=1; i<len; i++) result ^= nums[i]; return result; } };
相关文章推荐
- uva 12223 - Moving to Nuremberg
- 天声人語 20150608
- 【转】深圳的NB公司-四华一启
- Kafka+Spark Streaming+Redis实时系统实践
- Android应用插件式开发解决方法
- 挂载NTFS
- Two Sum 2015年6月8日
- 相机为什么需要镜头
- leetcode Implement strStr()
- python中if __name__ == '__main__': 的解析
- 使用ANT打包Android应用
- Python set模块使用方法
- 开发API查询工具
- 公司找人写一个软件 有酬劳
- python--列表,元组
- 函数式编程初探
- route
- 关系代数的问题与尝试(1)数据处理与代数
- 30分钟泛型教程
- 浅谈UML中类之间的五种关系及其在代码中的表现形式