FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaArithmetic/src/LeetCode/LeetCode137_no.java at master · Edwardlinge/JavaArithmetic · GitHub
Edwardlinge
JavaArithmetic
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaArithmetic
/
src
/
LeetCode
/
LeetCode137_no.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
26 lines (19 loc) · 706 Bytes
Breadcrumbs
JavaArithmetic
/
src
/
LeetCode
/
LeetCode137_no.java
Copy path
File metadata and controls
26 lines (19 loc) · 706 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package
LeetCode
;
public
class
LeetCode137_no
{
//思路:其他元素都出现了三次,按位计算每一位上1的个数,结果模3为1的那些位就是所求数二进制1所在的位。
// 出处:https://blog.csdn.net/w8253497062015/article/details/80058180
public
static
int
singleNumber
(
int
[]
nums
) {
int
result
=
0
;
for
(
int
i
=
0
;
i
<
32
;
i
++) {
int
mask
=
1
<<
i
;
int
count
=
0
;
for
(
int
j
=
0
;
j
<
nums
.
length
;
j
++) {
if
((
mask
&
nums
[
j
]) !=
0
)
count
++;
}
if
(
count
%
3
==
1
)
result
=
mask
|
result
;
}
return
result
;
}
}
Back
|
FazBrowse Home
|
New Git URL