Javascript one-liner


  • -2
    E
    var isPowerOfTwo = function(n) {
        return n.toString(2).split("").reduce((prev,curr)=>parseInt(prev)+parseInt(curr))=="1"; // either a string "1" or an integer 1
    };

Log in to reply
 

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