【Leetcode】Reverse Bits

Reverse bits of a given 32 bits unsigned integer.

class Solution:

    # @param n, an integer

    # @return an integer

    def reverseBits(self, n):

        ret = 0

        for i in range(32):

            ret = (ret<<1)+(n&1)

            n>>=1

        return ret

1 此处特别注意,n>>1和n>>=1不一样

你可能感兴趣的:(【Leetcode】Reverse Bits)