LeetCode题解:Single Number II
2016-02-09 17:30
363 查看
Given an array of integers, every element appears three times except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
题意:给定整数数组,除了某个数,其余数都出现3次。找出那个数。要求O(n)时间,O(1)空间
思路:看不懂……据说通过电路分析和卡诺图可以得到式子
代码:
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
题意:给定整数数组,除了某个数,其余数都出现3次。找出那个数。要求O(n)时间,O(1)空间
思路:看不懂……据说通过电路分析和卡诺图可以得到式子
代码:
public int singleNumber(int[] A) { int ones = 0, twos = 0; for(int i = 0; i < A.length; i++){ ones = (ones ^ A[i]) & ~twos; twos = (twos ^ A[i]) & ~ones; } return ones; }
相关文章推荐
- [转]Java_List元素的遍历和删除
- spring【2】( web.xml配置中classpath:与classpath*:的区别)
- 网页自适应屏幕大小
- 拼搏在编程的路上
- java.io.FileNotFoundException 和 requestFeature() must be called before adding content
- 最长公共子串
- 团队建设(Team building)就是等于组织大家一起吃饭娱乐吗?
- UIView 与 CALayer
- 读书笔记(四)
- POJ3150 矩阵的幂(难)
- 什么是闭包(Closure)?
- hdu 5623 KK's Number dp 博弈
- Android Material Design theme
- 设置交叉编译环境
- 11.IDA-this指针
- HTML5 Canvas之填充样式
- linux系统分区
- 数据输入输出加速
- 【小白的CFD之旅】04 任务
- JBoss 6.1安装配置问题