1. Description
2. Solution
- Version 1
class Solution {
public:
bool isPowerOfFour(int num) {
return !(num & (num - 1)) && (num & 0x55555555);
}
};
- Version 2
class Solution {
public:
bool isPowerOfFour(int num) {
return num > 0 && (num & (num - 1)) == 0 && (num - 1) % 3 == 0;
}
};
- Version 3
class Solution {
public:
bool isPowerOfFour(int num) {
return fmod(log10(num) / log10(4), 1) == 0;
}
};