My 8ms solution


  • 0
    T
    class Solution {
    public:
        bool isPowerOfTwo(int n) {
            int count=0;
            if(n<=0)
            {
                return false;
            }
            for(int i=0;i<sizeof(n)*8;i++)
            {
                if((n>>i) & (unsigned int)(0x01))
                {
                    count++;
                }
                if(count>1){
                    return false;
                }
            }
        }
    };

Log in to reply
 

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