We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d893c31 commit 1dc03bcCopy full SHA for 1dc03bc
solution/007.Reverse Integer/Solution2.py
@@ -0,0 +1,5 @@
1
+class Solution:
2
+ def reverse(self, x):
3
+ s = cmp(x,0) #提取此输入数字的符号
4
+ r = int(`x*s`[::-1]) #先作为字符串输入,然后转回整型
5
+ return r*s * (r<2**31) #防止溢出,小于的情况下返回true,否则为false
0 commit comments