Skip to content

Commit 4925b5d

Browse files
Update 009_Palindrome_Number.py
1 parent a80797b commit 4925b5d

File tree

1 file changed

+3
-17
lines changed

1 file changed

+3
-17
lines changed

009_Palindrome_Number.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
11
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)
2+
def isPalindrome(self, x: int) -> bool:
3+
temp = x
4+
return True if str(temp) == str(x)[::-1] else False

0 commit comments

Comments
 (0)