[LeetCode] Single Number II
2014-04-02 21:02
344 查看
int singleNumber(int A[], int n) { const int W = sizeof(int) * 8; // 整数字长 int count[W]; // 每个位上1 出现的次数 fill_n(&count[0], W, 0); for (int i = 0; i < n; i++) { for (int j = 0; j < W; j++) { count[j] += (A[i] >> j) & 1; count[j] %= 3; } } //展示数组中的结果 for(int i = W-1; i >= 0; i--) { cout<<count[i]; } cout<<endl; int result = 0; for (int i = 0; i < W; i++) { result += (count[i] << i); } return result; }
相关文章推荐
- c语言程序设计
- fedora 安装chrome
- 【数学】欧拉函数和相关结论
- 简单的ajax登陆验证
- C++ 常量区 堆区 栈区
- linux系统之编译内核实现iptables应用层过滤
- There will be decreasing performance of oracle by delete whole table and then insert ...
- DICOM中几个判断图像方向的tag
- php中urlencode与rawurlencode的区别
- ffmpeg使用
- HDU 2896 病毒侵袭
- git常用命令
- Web开发中常用的linux命令 详解
- Apollo Rule Reverse
- Matlab GUI保存图片
- 排序专题
- 米兰达可儿上演辣妈正传 美胸翘臀玩诱惑!
- 一步步学习微软InfoPath2010和SP2010--第十一章节--创建批准流程(3)--表单视图
- ACM计算几何题目推荐
- Web开发中Linux下常用命令和应用部署