Skip to content

Commit cdce4bc

Browse files
refactor 231
1 parent 55e6e16 commit cdce4bc

File tree

1 file changed

+11
-12
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+11
-12
lines changed
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
package com.fishercoder.solutions;
22

3-
/**231. Power of Two
3+
/**
4+
* 231. Power of Two
45
*
5-
* Given an integer, write a function to determine if it is a power of two.*/
6+
* Given an integer, write a function to determine if it is a power of two.
7+
*/
68

79
public class _231 {
8-
public boolean isPowerOfTwo(int n) {
9-
//after writing out the binary representation of some numbers: 1,2,4,8,16,32, you can easily figure out that
10-
//every number that is power of two has only one bit that is 1
11-
//then we can apply that cool trick that we learned from {@link easy._191}: n&(n-1) which will clear the least significant bit in n to zero
12-
return n > 0 && (n & (n - 1)) == 0;
13-
}
14-
15-
public static void main(String... strings) {
16-
_231 test = new _231();
17-
System.out.println(test.isPowerOfTwo(14));
10+
public static class Solution1 {
11+
public boolean isPowerOfTwo(int n) {
12+
//after writing out the binary representation of some numbers: 1,2,4,8,16,32, you can easily figure out that
13+
//every number that is power of two has only one bit that is 1
14+
//then we can apply that cool trick that we learned from {@link easy._191}: n&(n-1) which will clear the least significant bit in n to zero
15+
return n > 0 && (n & (n - 1)) == 0;
16+
}
1817
}
1918
}

0 commit comments

Comments
 (0)