python实现leetcode-第七题-整数反转
2019-01-14 21:24
399 查看
[code]import math class Solution: def reverse(self, x): """ :type x: int :rtype: int """ strX = str(x) if strX[0] != '-': strX1 = strX[::-1] x = int(strX1) if x >-2147483648 and x <2147483647: x = x else: x = 0 else: strX1 = strX[1:][::-1] x = -1*int(strX1) if x >-2147483648 and x <2147483647: x = x else: x = 0 return x
注意:
1 python自带的字符串操作
2 注意判断溢出,判断正负号
3 python中的与操作是and而不是&
相关文章推荐
- leetcode的python实现 刷题笔记7: 反转整数
- LeetCode 第七题 反转整数
- LeetCode--Reverse Integer(整数反转)Python
- LeetCode第七题--反转32位的整数
- leetcode的python实现 刷题笔记13: 罗马数字转整数
- 【leetcode】Reverse Integer整数反转----Java代码实现
- 编程集训第2天:LeetCode--环形链表2(142)及单链表反转(206)C++和python代码实现
- [leetcode 7] Reverse Integer(整数反转) c函数实现
- python入门习题——7,反转整数(简单)
- leetcode 【 Maximum Subarray 】python 实现
- LeetCode 79 Word Search (Python详解及实现)
- LeetCode 81 Search in Rotated Sorted Array II (Python详解及实现)
- LeetCode - 7. 反转整数
- LeetCode 30. Substring with Concatenation of All Words----Python实现
- python实现计算字符串中的整数的总和
- 位运算实现反转字节和求二进制整数中1的个数(无循环)
- LeetCode 72. Edit Distance-----Python实现
- LeetCode--Reverse Linked List 反转链表(Python)
- LeetCode 71 Simplify Path(Python详解及实现)
- leetcode 7. 反转整数(c++版)