C++ one line with bitset


  • 0
    M
    class Solution {
    public:
        bool isPowerOfTwo(int n) {
            return n > 0 && bitset<32>(n).count() == 1; 
        }
    };

Log in to reply
 

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