Skip to content

Commit 0c677f0

Browse files
authored
Merge pull request doocs#19 from zhanary/master
add two solutions with python
2 parents 597fc7b + d26f0b2 commit 0c677f0

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Solution(object):
2+
def isPalindrome(self, x):
3+
a = cmp(x,0)
4+
s = a*x
5+
y = int(`s`[::-1])
6+
return (x == y)

0 commit comments

Comments
 (0)