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

来源:互联网 发布:淘宝店铺主页 编辑:程序博客网 时间:2024/06/05 20:27

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

速度不是很快,但是行数少,这道题简单,没啥好说的。

0 0