Javascript Solution


  • 0
    B
    var str = num.toString(2);
    var ans = "";
    for(var i = 0; i < str.length; i++) {
        ans = ans + (str.charAt(i) === "0" ? "1" : "0");
    }
    return parseInt(ans, 2);

Log in to reply
 

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