Javascript solution using recursion


  • 0
    F

    This solution is a very simple one.

    var isPowerOfTwo = function(n) {
        if(n === 0){
            return false;
        }
        if(n === 1){
            return true;
        }
        if(n !== Math.floor(n)){
            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.