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

Appearance settings

Latest commit

 

History

History
History
36 lines (29 loc) · 778 Bytes

File metadata and controls

36 lines (29 loc) · 778 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Solution {
public boolean isPowerOfTwo(int n) {
//edge case
if(n<=0)
return false;
// bitwise soln the bit representation of n and n-1 for power of two number will be always zero;
return (n & (n-1)) ==0;
}
}
//class Solution {
// public boolean isPowerOfTwo(int n) {
// return ((n & (n-1)) == 0 && n>0);
// }
// }
//Brtureforce soln
//class Solution {
// private int pow2(int i){
// return (int)Math.pow(2,i);
// }
// public boolean isPowerOfTwo(int n) {
// for(int i=0;i<32;i++){
// if(n==pow2(i))
// return true;
// if(pow2(i)>n+1)
// return false;
// }
// return false;
// }
// }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.