Skip to content

Commit 64ec7d7

Browse files
authored
Create palindrome_number.py
1 parent 88e488e commit 64ec7d7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

palindrome_number.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution:
2+
"""
3+
@param num: a positive number
4+
@return: true if it's a palindrome or false
5+
"""
6+
def isPalindrome(self, num):
7+
# write your code here
8+
s = str(num) # 转字符串以免溢出
9+
i, j = 0, len(s) - 1
10+
while i < j:
11+
if s[i] == s[j]:
12+
i += 1
13+
j -= 1
14+
else:
15+
return False
16+
return True
17+
18+
# easy: https://www.lintcode.com/problem/palindrome-number

0 commit comments

Comments
 (0)