-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path342.cpp
More file actions
23 lines (23 loc) · 698 Bytes
/
342.cpp
File metadata and controls
23 lines (23 loc) · 698 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
__________________________________________________________________________________________________
sample 4 ms submission
class Solution {
public:
bool isPowerOfFour(int num) {
return 0x0 < num && !(num & 0xAAAAAAAA) && ((num&(num-1)) == 0);
}
};
__________________________________________________________________________________________________
sample 7880 kb submission
class Solution {
public:
bool isPowerOfFour(int num) {
if(num <= 0)
return false;
while(num % 4 == 0)
{
num /= 4;
}
return num == 1;
}
};
__________________________________________________________________________________________________