Leetcode

Leetcode 342. Power of Four

2018-09-04  本文已影响1人  SnailTyan

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

Power of Four

2. Solution

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

Reference

  1. https://leetcode.com/problems/power-of-four/description/
上一篇 下一篇

猜你喜欢

热点阅读