Skip to content

Commit e7fd30a

Browse files
Create 009_Palindrome_Number.py
1 parent 0320888 commit e7fd30a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

009_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+
# @return a boolean
3+
def isPalindrome(self, x):
4+
if x < 0:
5+
return False
6+
copy, reverse = x, 0
7+
8+
while copy:
9+
reverse *= 10
10+
reverse += copy % 10
11+
copy /= 10
12+
13+
return x == reverse
14+
15+
if __name__ == "__main__":
16+
print Solution().isPalindrome(98789)
17+
print Solution().isPalindrome(36726)
18+
print Solution().isPalindrome(-45654)

0 commit comments

Comments
 (0)