Share my python solution


  • 1
    class Solution:
    # @param n, an integer
    # @return an integer
    def reverseBits(self, n):
        ans = cnt = 0
        while n:
            ans = (ans<<1) + (n&1)
            n >>=1
            cnt+=1
        return ans<<(32-cnt)

Log in to reply
 

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