4ms C solution one-liner


  • 0
    G
    bool isPowerOfTwo(int n) {
        // 0x00000100 ^ 0x00000011 == (0x00000100 << 1) - 1
        return ((n > 0) && ((n ^ (n - 1)) == (n << 1) - 1));
    }

Log in to reply
 

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