share my c++ solution beats 83%


  • 1
    L

    class Solution {
    public:
    bool isPowerOfFour(int num) {
    if (num <= 0) return false; // 0 or negative
    else if ((num-1)&num) return false; // not power of 2
    else return num & 0x555555555555; // only allow 1 occur in odd bit
    }
    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.