Power of Four

2019-05-25 22:48:05 浏览数 (1)

1. Description

2. Solution

  • Version 1
代码语言:javascript复制
class Solution {
public:
    bool isPowerOfFour(int num) {
        return !(num & (num - 1)) && (num & 0x55555555);
    }
};
  • Version 2
代码语言:javascript复制
class Solution {
public:
    bool isPowerOfFour(int num) {
        return num > 0 && (num & (num - 1)) == 0 && (num - 1) % 3 == 0;
    }
};
  • Version 3
代码语言:javascript复制
class Solution {
public:
    bool isPowerOfFour(int num) {
        return fmod(log10(num) / log10(4), 1) == 0;
    }
};

0 人点赞