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

Commit1ee9a95

Browse files
EASY/src/easy/PowerOfTwo.java
1 parent447a272 commit1ee9a95

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

‎EASY/src/easy/PowerOfTwo.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ public boolean isPowerOfTwo(int n) {
99
//after writing out the binary representation of some numbers: 1,2,4,8,16,32, you can easily figure out that
1010
//every number that is power of two has only one bit that is 1
1111
//then we can apply that cool trick that we learned from {@link easy.NumberOfIBits}: n&(n-1) which will clear the least significant bit in n to zero
12-
if(n <=0)returnfalse;
13-
return (n&(n-1)) ==0;
12+
returnn>0 && (n&(n-1)) ==0;
1413
}
1514

1615
publicstaticvoidmain(String...strings){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp