4 MS C++ 93%. Nothing fancy but it works.


  • 0
    P
    class Solution {
    public:
        bool isPowerOfTwo(int n) {
            if(n == 1) return true;
            if(n ==0 ) return false;
            while(!(n & 1))
            {
                n = n >> 1;
                if(n == 1) return true;
            }
            return false;
        }
    };

Log in to reply
 

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