Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcdce4bc

Browse files
refactor 231
1 parent55e6e16 commitcdce4bc

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
packagecom.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
publicclass_231 {
8-
publicbooleanisPowerOfTwo(intn) {
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-
returnn >0 && (n & (n -1)) ==0;
13-
}
14-
15-
publicstaticvoidmain(String...strings) {
16-
_231test =new_231();
17-
System.out.println(test.isPowerOfTwo(14));
10+
publicstaticclassSolution1 {
11+
publicbooleanisPowerOfTwo(intn) {
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+
returnn >0 && (n & (n -1)) ==0;
16+
}
1817
}
1918
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp