Python, use bin() and int(s, 2), 99.42%


  • 0
    Z
    class Solution:
        # @param n, an integer
        # @return an integer
        def reverseBits(self, n):
            s = bin(n)[2:]
            s = '0' * (32-len(s)) + s
            num = int(s[::-1], 2)
            return num
    

Log in to reply
 

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