solution for JavaScript


  • 0
    H
    /**
     * @param {number} n - a positive integer
     * @return {number} - a positive integer
     */
    var reverseBits = function(n) {
        var arr = n.toString(2).split(''),
            len = 32 - arr.length
        for (var i = 0; i < len; i++) {
            arr.unshift('0')
        }
        return parseInt(arr.reverse().join(''), 2)
    };
    

Log in to reply
 

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