leetcode:Reverse Integer【Python版】
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版】的更多相关文章
- leetcode Reverse Integer python
class Solution(object): def reverse(self, x): """ :type x: int :rtype: int "&quo ...
- LeetCode: Reverse Integer 解题报告
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, retur ...
- [LeetCode] Reverse Integer 翻转整数
Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 click to ...
- leetcode reverse bits python
Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (re ...
- C++ leetcode::Reverse Integer
第一天上课,数据库老师说对于计算机系的学生,凡是在课本上学到的专业知识都是过时的.深以为然,感觉大学两年半真的不知道学了什么,为未来感到担忧,C++也不敢说是精通,入门还差不多.最近丧的不行,不管怎么 ...
- [Leetcode] reverse integer 反转整数
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 click to ...
- LeetCode——Reverse Integer(逆置一个整数)
问题: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return –321 Ha ...
- Leetcode: Reverse Integer 正确的思路下-要考虑代码简化
题目: Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 Have ...
- LeetCode——Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 Have you ...
随机推荐
- English trip -- VC(情景课)1 D
Read 阅读 Welcome! Meet our new student. His first name is Ernesto. 欧内斯托 His last name is Delgado. 德尔 ...
- iterm2用法与技巧
1.设置窗口 定位到 [Preferences - Profiles - Window] 新窗口设定风格设为 [Top of Screen],这样每次新打开终端都会固定出现在屏幕的顶端且不会有窗口 ...
- python-day42--单表查询
1. 简单查询select * from employee;select name,salary from employee; 2. where条件 1.比较运算符:> &l ...
- 二叉树—-1(No.9HN省赛小题)
题目: 1013: Prototypes analyze 时间限制: 1 Sec 内存限制: 128 MB提交: 6 解决: 4[提交][状态][讨论版] 题目描述 ALpha Ceiling M ...
- 上传xslx文件设置accept的MIME 类型
.dotx:application/vnd.openxmlformats-officedocument.wordprocessingml.template.docx:application/vnd.o ...
- PHP:第四章——PHP数组添加,删除,插入,分割,合并,及运算符
<pre> <?php header("Content-Type:text/html;charset=utf-8"); /*知识点一:赋值运算符 = 代码示例:数 ...
- learning uboot part command
=> part --helppart - disk partition related commands Usage:part uuid <interface> <dev> ...
- linux physical and virtual addressing modes
example 1: 特理地址和虚拟地址一致 Physical addressing mode requires no page tables and the CPU does not attempt ...
- 微信小程序-隐藏和显示自定义的导航
微信小程序中不能直接操作window对象,document文档,跟html的树结构不相同. 实现类似导航的隐藏显示,如图效果: 点击网络显示或隐藏网络中包含的内容.其他类似. 如果是jquery很方便 ...
- Criteria 使用指南
转自:http://www.blogjava.net/jerry-zhaoj/archive/2009/03/03/257546.html Restrictions的几个常用限定查询方法如下表所示: ...