C++ Using popcount


  • 0
    P

    It may not be cross platform but...

    class Solution {
    public:
        bool isPowerOfTwo(int n) {
            return (n > 0) && __builtin_popcount(n) == 1;
        }
    };
    

Log in to reply
 

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