Easy solution for C++,3ms


  • 0
    M

    class Solution {
    public:
    bool isPowerOfTwo(int n) {
    if(n<0) return false;
    bitset<32> t(n);
    if(t.count() == 1) return true;
    else return false;

    }
    

    };

    • list item

Log in to reply
 

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