Accepted Java Solution


  • 1
    C
    public class Solution 
    {
        public boolean isPowerOfTwo(int n) 
        {
            if(n <= 0)
                return false;
            if(n == 1)
                return true;
            while( n > 1 && n % 2 == 0)
                n /= 2;
            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.