1、在进入while之前,保证x是非负的;

2、符号还是专门用flag保存

===================

3、另一思路:将integer转换成string,然后首位swap,直至中间;

 class Solution:
# @return an integer
def reverse(self, x):
ret = 0
flag = 1
if x < 0:
flag = -1
x *= -1
while(x!=0):
ret = ret*10+x%10
x = x/10
return ret*flag

leetcode:Reverse Integer【Python版】的更多相关文章

  1. leetcode Reverse Integer python

    class Solution(object): def reverse(self, x): """ :type x: int :rtype: int "&quo ...

  2. LeetCode: Reverse Integer 解题报告

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

  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. 多线程(JDK1.5的新特性互斥锁)

    多线程(JDK1.5的新特性互斥锁)(掌握)1.同步·使用ReentrantLock类的lock()和unlock()方法进行同步2.通信·使用ReentrantLock类的newCondition( ...

  2. LeetCode--069--x的平方根

    问题描述: 实现 int sqrt(int x) 函数. 计算并返回 x 的平方根,其中 x 是非负整数. 由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去. 示例 1: 输入: 4 输出: ...

  3. 20170706xlVBA根据工资汇总表生成个人工资条

    Sub NextSeven20170706001() Application.ScreenUpdating = False Application.DisplayAlerts = False Appl ...

  4. Python在七牛云平台的应用(二)图片瘦身

    (一)七牛云平台的图片瘦身功能简介:(引用自官网) 针对jpeg.png格式图片 瘦身后分辨率不变,格式不变. 肉眼画质不变. 图片体积大幅减少,节省 CDN 流量 官网给的图片压缩率很高,官网给的「 ...

  5. 新建 ASP.NET MVC 项目快速代码

    视图模型- PagingInfo 类: public class PagingInfo { public int TotalItems { get; set; } public int ItemsPe ...

  6. Oracle 小函数的使用

    1.Oracle 正则表达式 经常会有一种需求是查询某个字符在字符串中的数量,可以使用正则表达式regexp_count函数 比如 SELECT regexp_count('0,1,1',',') f ...

  7. Vue--- 手动禁止ESlint

    使用vue-cli构建项目时,通常会问你要不要 “Use ESlint to lint your code?” 建议使用,这样会有助于规范我们的代码(这也是一种审美),ESlint的规范就不说了,写多 ...

  8. IE 11 回车事件代码不起作用但是在chrom可以正常运行解决办法

    今天遇到这个问题,搞半天开始以为是代码写错了,后面拿到chrom上执行发现是正常的,就是这段代码 function EnterPress(){          if(event.keyCode == ...

  9. CodeIgniter $this->db->where()的自定义语句写法问题

    .自定义字符串:你可以手动的编写子句:$where = "name='Joe' AND status='boss' OR status='active'"; $this->d ...

  10. L1-038 新世界

    这道超级简单的题目没有任何输入. 你只需要在第一行中输出程序员钦定名言“Hello World”,并且在第二行中输出更新版的“Hello New World”就可以了. 输入样例: 无 输出样例: H ...