赞
踩
Reverse bits of a given 32 bits unsigned integer.
Note:
Decompose into bits and reassemble.
class Solution:
def reverseBits(self, n: int) -> int:
buf = []
for i in range(32):
buf.append(n%2)
n = n // 2
ans = 0
for i in range(32):
ans = ans * 2 + buf[i]
return ans
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。