Skip to content

Latest commit

 

History

History
23 lines (19 loc) · 764 Bytes

342.md

File metadata and controls

23 lines (19 loc) · 764 Bytes

下面是别人的解答,只能说自己是个智障

bool isPowerOfFour(int num) {
    return num > 0 && (num & (num - 1)) == 0 && (num - 1) % 3 == 0;
}

//注意位运算优先级,谢谢pp

class Solution {
public:
    bool isPowerOfFour(int num) {
        if(num <= 0) return false;
        return num == 1 || (0xfffffffb&num) == 0 || (0xffffffef&num) == 0 || (0xffffffbf&num) == 0 || (0xfffffeff&num) == 0 ||
                (0xfffffbff&num) == 0 || (0xffffefff&num) == 0 || (0xffffbfff&num) == 0 || (0xfffeffff&num) == 0 ||
                (0xfffbffff&num) == 0 || (0xffefffff&num) == 0 || (0xffbfffff&num) == 0 || (0xfeffffff&num) == 0 ||
                (0xfbffffff&num) == 0 || (0xefffffff&num) == 0 || (0xbfffffff&num) == 0;
    }
};