Skip to content

Commit 829e7ac

Browse files
009_Palindrome_Number Python 3 Support (qiyuangong#26)
* Upgrade 009_Palindrome_Number.py for Python 3 support, by @peterhuang1kimo
1 parent 6699908 commit 829e7ac

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

python/009_Palindrome_Number.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,17 @@ class Solution(object):
99
def isPalindrome(self, x):
1010
if x < 0:
1111
return False
12-
ls = 0
12+
ls = len(str(x))
1313
tmp = x
14-
while tmp != 0:
15-
ls += 1
16-
tmp = tmp // 10
17-
tmp = x
18-
for i in range(ls/2):
19-
right = tmp % 10
14+
for i in range(int(ls/2)):
15+
right = int(tmp % 10)
2016
left = tmp / (10 ** (ls - 2 * i - 1))
21-
left = left % 10
22-
# print left, right
17+
left = int(left % 10)
2318
if left != right:
2419
return False
2520
tmp = tmp // 10
2621
return True
2722

28-
2923
# def isPalindrome(self, x):
3024
# #leetcode book
3125
# if x < 0:
@@ -62,4 +56,4 @@ def isPalindrome(self, x):
6256
if __name__ == '__main__':
6357
# begin
6458
s = Solution()
65-
print s.isPalindrome(1001)
59+
print s.isPalindrome(1001)

0 commit comments

Comments
 (0)