您的位置:首页 > 编程语言 > Python开发

Leetcode 7. Median of Two Sorted Arrays The Solution of Python

2017-04-04 21:32 465 查看
Reverse digits of an integer.

Example1: x = 123, return 321

Example2: x = -123, return -321

Note:

The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed integer overflows.

Python:

class Solution(object):
def reverse(self, x):
"""
:type x: int
:rtype: int
"""
x=int(str(x)[::-1]) if x>=0 else 0-int(str(abs(x))[::-1])
return 0 if x>2**31-1 or x<-2**31 else x


速度不是很快,但是行数少,这道题简单,没啥好说的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python leetcode