class Solution(object):
def reverse(self, x):
"""
:type x: int
:rtype: int
"""
answer = 0 sign = 1 if x > 0 else -1
x = abs(x)
while x > 0:
answer = answer * 10 + x % 10
x/=10
if answer > 2147483647:
answer = 0
return sign*answer

leetcode Reverse Integer python的更多相关文章

  1. LeetCode: Reverse Integer 解题报告

    Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, retur ...

  2. leetcode:Reverse Integer【Python版】

    1.在进入while之前,保证x是非负的: 2.符号还是专门用flag保存 =================== 3.另一思路:将integer转换成string,然后首位swap,直至中间: cl ...

  3. [LeetCode] Reverse Integer 翻转整数

    Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 click to ...

  4. leetcode reverse bits python

    Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (re ...

  5. C++ leetcode::Reverse Integer

    第一天上课,数据库老师说对于计算机系的学生,凡是在课本上学到的专业知识都是过时的.深以为然,感觉大学两年半真的不知道学了什么,为未来感到担忧,C++也不敢说是精通,入门还差不多.最近丧的不行,不管怎么 ...

  6. [Leetcode] reverse integer 反转整数

    Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 click to ...

  7. LeetCode——Reverse Integer(逆置一个整数)

    问题: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return –321   Ha ...

  8. Leetcode: Reverse Integer 正确的思路下-要考虑代码简化

    题目: Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 Have ...

  9. LeetCode——Reverse Integer

    Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 Have you ...

随机推荐

  1. 我的经常使用linux小命令

        这里并非系统具体介绍每个Linux命令,不过记录本人在平时工作中经经常使用到的一些比較基础的命令及相关的參数,同一时候用了一些简单的样例来说明这些命令的用途,以及怎样用多种命令来实现同一种功能 ...

  2. TCPDUMP详解(续)

    TCPdump抓包命令  tcpdump是一个用于截取网络分组,并输出分组内容的工具.tcpdump凭借强大的功能和灵活的截取策略,使其成为类UNIX系统下用于网络分析和问题排查的首选工具.  tcp ...

  3. 【转载】VS2010+VMWare8+VisualDDK1.5.6 创建并调试驱动程序 - 完全教程

    原帖:http://techird.blog.163.com/blog/static/1215640362011112385241568/ 本文描述了如何使用Visual Studio+VMMare+ ...

  4. Silverlight代码编写对控件的PlaneProjection.RotationY属性控制动画

    Canvas c; void btnDraw_Click(object sender, RoutedEventArgs e) { Storyboard story = new Storyboard() ...

  5. Built-in Functions学习

    abs(x) :返回一个数字的绝对值,可以是整形也可以是浮点型. all(iterable):返回True,如果所以迭代对象的元素为true,或者可迭代对象为空. any(iterable):如果可迭 ...

  6. C++ Placement New

    先看一个题目: #include <stdio.h> #include <iostream> using namespace std; struct Base { int j; ...

  7. 发布MFC ActiveX控件并实现自动更新

    一.        引言 上一篇我们讲了如何使用 VC 2005来开发 MFC ActiveX控件,我们开发 ActiveX控件最终目的是将 ActiveX控件发布出来并嵌入在 Web网页中,随着控件 ...

  8. 群星云集 BOSS上海时装秀—情沪魅影- 在线观看 - 乐视网

    群星云集 BOSS上海时装秀-情沪魅影- 在线观看 - 乐视网 群星云集 BOSS上海时装秀-情沪魅影

  9. linux环境之监听端口配置

    export JAVA_OPTS="-Dcom.sun.management.jmxremote.port=18950 -Dcom.sun.management.jmxremote.auth ...

  10. MFC的命令行

    一个程序,我们通过输入不同的命令行参数,就可以实现一个可执行文件,多种功能,通过命令行来控制它的行为,例如,我们在控制台的时候,就是遇到最多的,如一个exe程序,加入为test..exe,我们可以设置 ...