Java [Leetcode 137]Single Number II
题目描述:
Given an array of integers, every element appears three times except for one. Find that single one.
解题思路:
具体参考Detailed explanation and generalization of the bitwise operation method for single numbers
讲的实在是很全面,而且拓展到了一般的情况,膜!!
代码如下:
public class Solution{
public int singleNumber(int[] nums){
int x1 = 0;
int x2 = 0;
int mask = 0; for(int i : nums){
x2 ^= x1 & i;
x1 ^= i;
mask = ~(x1 & x2);
x2 &= mask;
x1 &= mask;
} return x1;
}
}
Java [Leetcode 137]Single Number II的更多相关文章
- LeetCode 137. Single Number II(只出现一次的数字 II)
LeetCode 137. Single Number II(只出现一次的数字 II)
- Leetcode 137 Single Number II 仅出现一次的数字
原题地址https://leetcode.com/problems/single-number-ii/ 题目描述Given an array of integers, every element ap ...
- [LeetCode] 137. Single Number II 单独数 II
Given a non-empty array of integers, every element appears three times except for one, which appears ...
- LeetCode 137 Single Number II(仅仅出现一次的数字 II)(*)
翻译 给定一个整型数组,除了某个元素外其余的均出现了三次. 找出这个元素. 备注: 你的算法应该是线性时间复杂度. 你能够不用额外的空间来实现它吗? 原文 Given an array of inte ...
- [LeetCode] 137. Single Number II 单独的数字之二
Given a non-empty array of integers, every element appears three times except for one, which appears ...
- 详解LeetCode 137. Single Number II
Given an array of integers, every element appears three times except for one, which appears exactly ...
- Java for LeetCode 137 Single Number II
Given an array of integers, every element appears three times except for one. Find that single one. ...
- leetcode 137. Single Number II ----- java
Given an array of integers, every element appears three times except for one. Find that single one. ...
- LeetCode 137 Single Number II 数组中除了一个数外,其他的数都出现了三次,找出这个只出现一次的数
Given an array of integers, every element appears three times except for one, which appears exactly ...
随机推荐
- CSS3属性box-shadow使用教程,css3box-shadow
CSS3的box-shadow属性可以让我们轻松实现图层阴影效果.我们来实战详解一下这个属性. 1. box-shadow属性的浏览器兼容性先来看一个这个属性的浏览器兼容性: Opera: 不知道是从 ...
- 并查集 基础 AC 2014-01-14 13:37 202人阅读 评论(0) 收藏
题目地址:http://haut.openjudge.cn/20131112/6/ 求编号最多的组 查看 提交 统计 提问 总时间限制: 1000ms 内存限制: 63353kB 描述 相邻两个 ...
- WCF 基础
ServiceModel 配置元素 Binding 配置元素: 客户端Web.config: <?xml version="1.0" encoding="utf-8 ...
- PHP对XML添加节点之appendChild()方法讲解
问题如下:<b > <c>test</c> </b>我要在b节点里面添加一个子节点比如说加一个d节点,要实现成<b > <c>t ...
- fedora下缺少autopoint包的解决办法
编译过程中,报错,缺少autopoint包 然而无论是yum install autopoint 还是yum search autopoint都没有理想的答案 执行yum install gettex ...
- JsRender系列demo(7)compline
<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery.j ...
- java基础知识回顾之java Thread类学习(四)--java多线程安全问题(锁)
上一节售票系统中我们发现,打印出了错票,0,-1,出现了多线程安全问题.我们分析为什么会发生多线程安全问题? 看下面线程的主要代码: @Override public void run() { // ...
- POJ1860Currency Exchange(SPFA)
http://poj.org/problem?id=1860 题意: 题目中主要是说存在货币兑换点,然后现在手里有一种货币,要各种换来换去,最后再换回去的时候看能不能使原本的钱数增多,每一种货币都有 ...
- hdu 4586 Play the Dice
思路:设期望值为s,前m个是再来一次机会,则有 s=(a[1]+s)/n+(a[2]+s)/n+……+(a[m]+s)/n+a[m+1]/n…… 化简:(n-m)s=sum 当sum=0时,为0: 当 ...
- cvc-elt.1: Cannot find the declaration of element---与spring 无关的schema 验证失败
晚上查了好久,都是spring 出这种问题的解决方式,终于查到为什么了. http://wakan.blog.51cto.com/59583/7218/ 转自这个人.. 多谢啦! 为了验证 XML 文 ...