首页 > 代码库 > 190. Reverse Bits 反转二进制
190. Reverse Bits 反转二进制
Reverse bits of a given 32 bits unsigned integer.
For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 00111001011110000010100101000000).
Follow up:
If this function is called many times, how would you optimize it?
Related problem: Reverse Integer
Credits:
Special thanks to @ts for adding this problem and creating all test cases.
将一个32位整型转成二进制后,反转,再转换回10进制
1 2 3 4 5 6 | class Solution: # @param n, an integer # @return an integer def reverseBits( self , n): reBin = ‘{0:b}‘ . format (n).zfill( 32 )[:: - 1 ] return int (reBin, 2 ) |
null
190. Reverse Bits 反转二进制
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。