Simple Ruby Solution


  • 0
    T
    def reverse_bits(n)
        number = 0
        counter = 1
        n.to_s(2).rjust(32, "0").each_char do |c|
            number += c.to_i*counter
            counter *=2
        end
        return number
    end
    

Log in to reply
 

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