Leetcode刷题 (python 3)7. 整数反转
2019-02-12 03:42
495 查看
给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转。
示例 1:
输入: 123
输出: 321
示例 2:
输入: -123
输出: -321
示例 3:
输入: 120
输出: 21
注意:
假设我们的环境只能存储得下 32 位的有符号整数,则其数值范围为 [−231, 231 − 1]。请根据这个假设,如果反转后整数溢出那么就返回 0。
#Python 3
class Solution: def reverse(self, x): """ :type x: int :rtype: int """ r=0 z=1 if (x < 0): z=-1 if (x< -2147483647 or x > 2147483646): z=0 x=abs(x) for i in range(len(str(x))): r=10*r+x%10 x=x//10 if (r< -2147483647 or r>2147483646): z=0 return(z*r)
相关文章推荐
- leetcode--整数反转--python
- leetcode的python实现 刷题笔记7: 反转整数
- LeetCode-Python-7. 整数反转
- LeetCode7.python实现:整数反转问题☆
- [leetcode 7] 整数反转 python
- LeetCode:整数反转(Python版本)
- leetcode_7.整数反转(python)
- python实现leetcode-第七题-整数反转
- LeetCode题解(python)-7. 整数反转
- Leetcode7.整数反转(python3)
- LeetCode--Reverse Integer(整数反转)Python
- [leetcode] Reverse Integer 反转整数
- leetcode 007 反转整数
- LeetCode7——Reverse Integer(将一个整数反转,注意溢出的处理)
- python解leetcode——13.Roman to Integer (罗马数字转为整数)
- leetcode--字符串转换为整数--python
- [Leetcode,python] Reverse String 反转字符串
- 力扣Python007:整数反转
- 用python写leetcode【5】 --字符串中的第一个唯一字符(387)、反转字符串(344)
- 【LeetCode】7. 整数反转