Power of Four
https://leetcode.com/problems/power-of-four/submissions/
class Solution {
public:
bool isPowerOfFour(int n) {
if(n <= 0){
return false;
}
if(n & (n - 1)){
return false;
}
return !(n & (0xAAAAAAAA)); // means ...10101010101010 and with n should be zero
}
};
Comments
Post a Comment