您的位置:首页 > 其它

Leetcode 342 Power of Four

2017-07-02 16:10 399 查看

Leetcode 342 Power of Four

using namespace std;
class Solution {
public:
bool isPowerOfFour(int num) {

if (num > 0 && 1073741824 % num == 0)//是2的幂次
if (num & 0x55555555)//2的幂次数中,4的幂次数,二进制的1都在奇数位上,而其他的像2,8,32这些,二进制的1都在偶数为上(最右一位为第一位)
return true;
return false;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  leetcode