C++ Solution Using Builtin PopCount


  • 0
    M
    class Solution {
    public:
        bool isPowerOfTwo(int n) {
            return n >= 0 ? __builtin_popcount(n) == 1 : false;
        }
    };
    

Log in to reply
 

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