Simple 3ms C solution

  • 0
    bool isPowerOfTwo(int n) {
        if(n<=0) return false;
        int bitOneCount = 0;
        int tmp;
        for(int i=0; i<32; i++){
            tmp = n>>i;
            tmp = tmp & 0x01;
                if(bitOneCount>1) return false;
        if(bitOneCount==0) return false;
        return true;

Log in to reply

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