File tree 2 files changed +23
-2
lines changed
2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change 1
- import slidingwindow . Problem992_SubarraysWithKDifferentIntegers ;
1
+ import bit . Problem_BitWiseANDofNumbersRange ;
2
2
3
3
public class Main {
4
4
5
5
public static void main (String [] args ) {
6
- Problem992_SubarraysWithKDifferentIntegers .run ();
6
+ Problem_BitWiseANDofNumbersRange .run ();
7
7
}
8
8
}
Original file line number Diff line number Diff line change
1
+ package bit ;
2
+
3
+ public class Problem_BitWiseANDofNumbersRange {
4
+
5
+ public static void run () {
6
+ Problem_BitWiseANDofNumbersRange solution = new Problem_BitWiseANDofNumbersRange ();
7
+ int a = 5 , b = 7 ;
8
+ int res = solution .rangeBitwiseAnd (a , b );
9
+ System .out .println (res );
10
+ }
11
+
12
+ public int rangeBitwiseAnd (int m , int n ) {
13
+ int i = 0 ; // i means we have how many bits are 0 on the right
14
+ while (m != n ){
15
+ m >>= 1 ;
16
+ n >>= 1 ;
17
+ i ++;
18
+ }
19
+ return m << i ;
20
+ }
21
+ }
You can’t perform that action at this time.
0 commit comments