Skip to content

Commit 1ee9a95

Browse files
EASY/src/easy/PowerOfTwo.java
1 parent 447a272 commit 1ee9a95

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) return false;
13-
return (n&(n-1)) == 0;
12+
return n> 0 && (n&(n-1)) == 0;
1413
}
1514

1615
public static void main(String...strings){

0 commit comments

Comments
 (0)