We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 50d69f2 commit bd19f16Copy full SHA for bd19f16
bin/.gitignore
@@ -0,0 +1 @@
1
+/com/
src/com/jie/SingleNumberTwo.java
@@ -0,0 +1,30 @@
+package com.jie;
2
+
3
+public class SingleNumberTwo {
4
5
+ public static void main(String[] args) {
6
+ // TODO Auto-generated method stub
7
8
+ }
9
10
+ public int singleNumber(int[] nums) {
11
+ int [] count = new int[32];
12
+ int result=0;
13
+ for(int i=0;i<32;i++){
14
+ for(int j=0;j<nums.length;j++){
15
+ //循环区得每一位之和 使用无符号向右移
16
+ count[i]+=(nums[j]>>>i)&1;
17
18
+ //获取那一个只出现了一次的数 因为除了一个每一个数都出现了三次 所以我们出现的数的
19
+ //和肯定是三的倍数 最后一个没有出现的数 要不然是0要不然是1 所以%3即可
20
+ count[i]=count[i]%3==0?0:1;
21
22
+ //构造最后的结果
23
24
25
+ result|=count[i]<<i;
26
27
+ return result;
28
29
30
+}
0 commit comments