One-line Ruby Solution


  • 2
    # @param {Integer} n, a positive integer
    # @return {Integer}
    def reverse_bits(n)
        2**(32-(n.to_s(2)).length())*n.to_s(2).reverse!.to_i(2)
    end

Log in to reply
 

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