【leetcode❤python】 7. Reverse Integer
#-*- coding: UTF-8 -*-
#2147483648
#在32位操作系统中,由于是二进制,
#其能最大存储的数据是1111111111111111111111111111111。
#正因为此,体现在windows或其他可视系统中的十进制应该为2147483647。
#32位数的范围是 -2147483648~2147483648
class Solution(object):
def reverse(self, x):
"""
:type x: int
:rtype: int
"""
x=int(str(x)[::-1]) if x>0 else -int(str(-x)[::-1])
return x if x<2147483648 and x>=-2147483648 else 0
【leetcode❤python】 7. Reverse Integer的更多相关文章
- 【leetcode❤python】 190. Reverse Bits
#-*- coding: UTF-8 -*- class Solution: # @param n, an integer # @return an integer def reve ...
- 【leetcode❤python】206. Reverse Linked List
# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# s ...
- 【leetcode❤python】Sum Of Two Number
#-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...
- 【leetcode❤python】 8. String to Integer (atoi)
#-*- coding: UTF-8 -*-#需要考虑多种情况#以下几种是可以返回的数值#1.以0开头的字符串,如01201215#2.以正负号开头的字符串,如'+121215':'-1215489' ...
- 【leetcode❤python】13. Roman to Integer
#-*- coding: UTF-8 -*-#从前向后遍历罗马数字,#如果某个数比前一个数小,则加上该数.反之,减去前一个数的两倍然后加上该数###-----技术规则-----#----------- ...
- 【leetcode❤python】 1. Two Sum
#-*- coding: UTF-8 -*- #AC源码[意外惊喜,还以为会超时]class Solution(object): def twoSum(self, nums, target): ...
- 【leetcode❤python】 58. Length of Last Word
#-*- coding: UTF-8 -*-#利用strip函数去掉字符串去除空格(其实是去除两边[左边和右边]空格)#利用split分离字符串成列表class Solution(object): ...
- 【LeetCode OJ】Evaluate Reverse Polish Notation
Problem link: http://oj.leetcode.com/problems/evaluate-reverse-polish-notation/ According to the wik ...
- 【LeetCode练习题】Evaluate Reverse Polish Notation
Evaluate Reverse Polish Notation Evaluate the value of an arithmetic expression in Reverse Polish No ...
随机推荐
- 《奥威Power-BI案例应用:带着漫画看报告》腾讯课程开课啦
元旦小假期过去了,不管是每天只给自己两次下床机会的你,还是唱K看电影逛街样样都嗨的你,是时候重振旗鼓,重新上路了!毕竟为了不给国家的平均工资水平拖后腿,还是要努力工作的.话说2016年已经过去了,什么 ...
- Git的.gitignore文件配置
.gitignore是Git工具的配置文件,用于屏蔽某些文件上传到线上. 创建.gitignore 在window系统中,不允许新建文件名以"."开头的文件,所以通过git bas ...
- Spark:读取hdfs gz压缩包
spark 1.5.1是支持直接读取gz格式的压缩包的,和普通文件没有什么区别: 使用spark-shell进入spark shell 交互界面: 输入命令: sc.textFile("\h ...
- Linux 使用本地yum源及软件包管理
[root@node130 rh]# pwd/opt/rh[root@node130 rh]# lsrhel-server-6.4-x86_64-dvd.iso [root@node130 rh]#m ...
- ANE 从入门到精通 --- 一键打包ANE
每次都要执行好几步才能编译出ANE很是麻烦,使用如下脚本 一键完成复杂的流程 REM 好压HaoZipC文件所在的位置,7Zip,WinRAR等均可 Set Zip=D:\"Program ...
- Access restriction: The type QName is not accessible due to restriction on required library
There's another solution that also works. I found it on this forum: Go to the Build Path settings in ...
- jquery-2.0.0
http://code.jquery.com/jquery-2.0.0.min.js (minified, for production) http://code.jquery.com/jquery- ...
- (转)学习使用Jmeter做压力测试(三)--数据库测试
数据库测试 JMeter可以做为Web服务器与浏览器之间的代理网关,以捕获浏览器的请求和Web服务器的响应,这样就可很容易的生成性能测试脚本. 根据脚本,JMeter可通过线程组来模拟真实用户对Web ...
- C#面向编程的三大特征
在面向对象的编程中,首先要清楚地理解面向对象编程的三个基本特征: 封装, 继承, 多态! 1.封装 更确切地说,是对象封装.就是每个对象都包含自己进行某种操作时所需要的所有信息,而不依赖于其他对象来完 ...
- asp.net 事件加载顺序
下面是母版页与内容页合并后事件的发生顺序: 母版页控件 Init 事件. 内容控件 Init 事件. 母版页 Init 事件. 内容页 Init 事件. 内容页 Load 事件. 母版页 Load 事 ...