-
-
Notifications
You must be signed in to change notification settings - Fork 297
/
Copy path1009.java
30 lines (29 loc) · 839 Bytes
/
1009.java
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
27
28
29
30
__________________________________________________________________________________________________
sample 0 ms submission
class Solution {
public int bitwiseComplement(int N) {
int X = 1;
while (N > X){
X = X * 2 + 1;
}
return X - N;
}
}
__________________________________________________________________________________________________
sample 31672 kb submission
class Solution {
public int bitwiseComplement(int N) {
if(N==0) return 1;
int r = 0;
int f = 1;
while(N!=0){
if((N&1)==0){
r = r + f;
}
f=f<<1;
N>>=1;
}
return r;
}
}
__________________________________________________________________________________________________