Reverse bits of a given 32 bits unsigned integer. Example 1: Input: 00000010100101000001111010011100 Output: 00111001011110000010100101000000 Explanation: The input binary string 00000010100101000001111010011100 represents the unsigned integer 432615
Reverse bits of a given 32 bits unsigned integer. Example 1: Input: 00000010100101000001111010011100 Output: 00111001011110000010100101000000 Explanation: The input binary string 00000010100101000001111010011100 represents the unsigned integer 432615
请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift 说明:题目中含有$符号则为付费题目. 如:[Swift]LeetCode156.二叉树的上下颠倒 $ Binary Tree Upside Down 请下拉滚动条查看最新 Weekly Contest!!! Swift LeetCode 目录 | Catalog 序 号 题名Title 难度 Difficulty 两数之
我的做法,,这个题在于必须补0 def reverseBits(n): num=32-len(bin(n)[2:]) m = bin(n)[2:][::-1] if num > 0: for i in range(num): m=m+'0' print(m,int(m,2)) return m 看到前几做法 nums=bin(n) nums=nums.lstrip('0b') nums=nums.zfill(32) #zfill 一直没找到....原来是这个 nums=nums[::-1] re