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