【leetcode❤python】 190. Reverse Bits
#-*- coding: UTF-8 -*-
class Solution:
# @param n, an integer
# @return an integer
def reverseBits(self, n):
tmp=str(bin(n))[2:][::-1]
for i in xrange(32-len(tmp)):
tmp+='0'
return int(tmp,base=2)
sol=Solution()
print sol.reverseBits(43261596)
【leetcode❤python】 190. Reverse Bits的更多相关文章
- 【leetcode❤python】 7. Reverse Integer
#-*- coding: UTF-8 -*-#2147483648#在32位操作系统中,由于是二进制,#其能最大存储的数据是1111111111111111111111111111111.#正因为此, ...
- 【leetcode❤python】206. Reverse Linked List
# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# s ...
- 【LeetCode】190. Reverse Bits 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 二进制字符串翻转 位运算 日期 题目地址:https://le ...
- 【一天一道Leetcode】#190.Reverse Bits
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 我的个人博客已创建,欢迎大家持续关注! 一天一道le ...
- 【LeetCode】190. Reverse Bits
题目: Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented ...
- 【刷题-LeetCode】190 Reverse Bits
Reverse Bits Reverse bits of a given 32 bits unsigned integer. Example 1: Input: 0000001010010100000 ...
- 【leetcode❤python】Sum Of Two Number
#-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...
- 【leetcode❤python】191. Number of 1 Bits
#-*- coding: UTF-8 -*- class Solution(object): def hammingWeight(self, n): if n<=0:retu ...
- 【leetcode❤python】 1. Two Sum
#-*- coding: UTF-8 -*- #AC源码[意外惊喜,还以为会超时]class Solution(object): def twoSum(self, nums, target): ...
随机推荐
- Array-练习-自定义功能
//html part <script type="text/javascript" src="out.js"></script> &l ...
- 使用 JavaScript 实现栈
1.栈的基本操作 function Stack() { //使用数组保存栈元素 var items = []; //添加新元素到栈顶(相当于数组的末尾) this.push = function(el ...
- CentOS7配置日志(VirtualBox)
版本为CentOS-Minimal 1.VirtualBox下安装CentOS. 新建虚拟机 下载CentOS,放入盘片,启动虚拟机,按提示开始安装(建议内存1G,硬盘10G以上) 2. 设置网络 ...
- PSR : php编码规范
诸王混战 关于开发标准这块,可以说一直都是风格迥异,各家都有各家的玩法,民间更是个人玩个人的.目前我们国内比较出名的几个框架(Yii,Laravel) 都已经支持Composer并且加入了PHP-FI ...
- 对list进行切片
取一个list的部分元素是非常常见的操作.比如,一个list如下: >>> L = ['Adam', 'Lisa', 'Bart', 'Paul'] 取前3个元素,应该怎么做? 笨办 ...
- ios 修改webView字体
UIFont *font = [UIFont systemFontOfSize:]; //方法一 NSString *fontColor =@"CCCCFF"; NSString ...
- ios 父VIew的宽度 等于较大view的宽度,并且垂直居中
白色view上面有两个子View,红色view和橙色view.白色view的宽度等于橙色view和红色view宽度较大的一个,并且橙色view和红色view垂直居中, Masonry布局如下: ...
- django for monkey(chapter one)
一.获取设备驱动 class monkey(object): def get_devices(self): self.a = os.popen('adb devices') self.devices ...
- centOS安装nginx
下载源码 wget http://nginx.org/download/nginx-1.10.1.tar.gz git clone https://bitbucket.org/nginx-goodie ...
- AngularJS Best Practices: pretty urls
By default, AngularJS will route URLs with a hashtag. For example: http://example.com/ http://exampl ...