8ms c++ solution


  • 3
    Z

    class Solution {
    public:
    bool isPowerOfTwo(int n) {

            while(n!=0&&n%2 == 0)
            {
                n = n/2;
            }
           return (n==1);
    }
    

    };


  • 0
    M
        if(n==0)
        return false;
        int bit=1;
        while(!(n&bit))
        {
            n>>=1;
        };
        if(n==1)
        {
            return true;
        }else
        {
            return false;
        };

Log in to reply
 

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