leetcode@ [136/137] Single Number & Single Number II
2015-11-18 14:42
375 查看
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?
View Code
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() == 1) return nums[0]; vector<int> bitNums(32, 0); int res = 0; for(int i=0;i<32;++i) { for(int j=0;j<nums.size();++j) { bitNums[i] += (nums[j] >> i) & 1; cout << ((nums[j] >> i) & 1) << " "; } cout<<endl; } for(int i=0;i<bitNums.size();++i) { res += (bitNums[i] % 3) << i; } return res; } };
View Code
相关文章推荐
- DataTable过滤重复字段
- 用this调用类的构造方法
- 全面解读Oracle同义词的概念作用、创建删除查看及Oracle的db link
- MVC4 无刷新分页!
- Java微信开发之公众号支付接口
- [leetcode] 174. Dungeon Game
- linux INIT_WORK 创建工作队列
- 关于Maven的传递依赖原则 nearest definition 的一个疑问
- 使用 Redis 实现分布式系统轻量级协调技术
- windows C 与 linux C区别?
- PHP获取目录下的文件(包括子目录中的文件)
- es中的scan and scroll搜索
- mysql数据库的左连接,右连接,内链接的区别
- 苹果开发者账号申请流程--企业
- HTML5 开发者需要了解的技巧和工具汇总
- CocoaPods
- 1.mysql学习笔记:mysql的源码安装
- 短信备份
- windows脚本隐藏执行
- css3更易操作的网页细节-box-shadow阴影