8 - leetcode Reverse Integer
2016-11-14 22:26
393 查看
注意越界问题…
#!/usr/bin/python # -*- coding: utf-8 -*- ''' 英文:Reverse digits of an integer. 中文:整数反转 举例: Example1: x = 123, return 321 Example2: x = -123, return -321 ''' class Solution(object): def reverse(self, x): """ :type x: int :rtype: int """ if x >= 0: sign = 1 else: x,sign = -x,-1 result = 0 while x: result = result * 10 + x % 10 x = int(x/10 ) #Python语言特性...整数越界没发现,易错点... if result < -2147483647 or result > 2147483647: return 0 return result * sign if __name__ == "__main__": a = Solution() print a.reverse(2147483647)
相关文章推荐
- LeetCode Reverse Integer
- leetcode——Reverse Integer
- leetcode——7—— Reverse Integer可仿溢出
- 【LeetCode】7 & 8 - Reverse Integer & String to Integer (atoi)
- Leetcode 07 Reverse Integer(数字反转) && 09 Palindrome number(回文判断)
- leetcode(7) - Reverse Integer
- Reverse Integer && Palindrome Number-LeetCode
- Leetcode:Reverse Integer
- Reverse Integer | LeetCode
- [leetcode]Reverse Integer 代码(C++)
- LeetCode-7-Reverse Integer-E
- Reverse Integer 翻转数字@LeetCode
- LeetCode Reverse Integer
- LeetCode之Reverse Integer
- leetcode:Reverse Integer(反转数字)【算法面试题】
- LeetCode-7-Reverse Integer(C语言实现)
- 【leetcode】Reverse Integer(middle)☆
- LeetCode: Reverse Integer
- LeetCode: Reverse Integer
- LeetCode[7]Reverse Integer