-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path201.java
More file actions
35 lines (31 loc) · 926 Bytes
/
201.java
File metadata and controls
35 lines (31 loc) · 926 Bytes
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
31
32
33
34
35
__________________________________________________________________________________________________
sample 4 ms submission
class Solution {
public int rangeBitwiseAnd(int m, int n) {
// int offset = 0;
// while (n != m) {
// m >>= 1;
// n >>= 1;
// offset++;
// }
// return m << offset;
while (n > m) {
n &= (n-1);
}
return n;
}
}
__________________________________________________________________________________________________
sample 33800 kb submission
class Solution {
public int rangeBitwiseAnd(int m, int n) {
int count = 0;
while (m != n) {
m >>= 1;
n >>= 1;
count++;
}
return (m <<= count);
}
}
__________________________________________________________________________________________________