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 ...
随机推荐
- 【C# 反射泛型】
C# 反射泛型 摘自:http://www.itwis.com/html/net/c/20110411/10175.html C#泛型反射和普通反射的区别,泛型反射和普通反射的区别就是泛型参数的处理上 ...
- make -f dc_debug.mak 提示错误"/usr/bin/ld:can not find -l***"解决办法
在公司不同服务器上"make -f ***"程序的时候,有的服务器可以编译通过,有的却提示"/usr/bin/ld:can not find -l***"的错误 ...
- linux源代码阅读笔记 find_entry分析
78 static struct buffer_head * find_entry(struct m_inode * dir, 79 const char * name, int namelen, s ...
- 【redis】05Redis的常用命令及高级应用
Redis常用命令 Redis提供了非常丰富的命令,对数据库和个中数据类型进行操作, 这些命令呢,可以在Linux终端使用. 分为两大类的命令,一种是键值相关的命令,一种是服务器相关的命令, ...
- Palindrome Partitioning II
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- 【leetcode】Median of Two Sorted Arrays(hard)★!!
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted ...
- POJ2151Check the difficulty of problems
题意 : 举办一次比赛不容易,为了不让题目太难,举办方往往希望能够讲出的题目满足两点,1是所有的队伍都至少能够解出一个题目,2是冠军队至少能解出确定数量的题目,最后让你求的是每个队伍至少解出一道题并且 ...
- TVM 下载监控
iftop -n -i em1 -F 218.26.188.220/32 到10.10.81.23上用上面的语句看山西的流量. 到/opt/data/log/下看日志 到/opt/data/tvmca ...
- http://www.yihaomen.com/article/java/302.htm
http://www.yihaomen.com/article/java/302.htm
- Ubuntu 14.04 + Linux 3.14.34 系统调用实现文件拷贝
采用 64位系统, ubuntu 14.04 + 新内核linux-3.14.34 下载地址https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.1 ...