Java 3 lines answer (using recursive)


  • 0
    N
    public boolean isPowerOfTwo(int n) {
        
        if(n==1) return true ; 
        else if ( n%2==1 || n==0 ) return false ;
        
        return isPowerOfTwo(n/2);
        
    }

Log in to reply
 

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