class Solution:
def isPalindrome(self, x):
"""
:type x: int
:rtype: bool
"""
string = str(x)
i, j = 0, len(string) - 1
while i != j:
if string[i] != string[j]:
return False
if i == len(string) / 2:
return True
i += 1
j -= 1
return True
x = 12321
sol = Solution()
print(sol.isPalindrome(x))
【leetcode】回文数(Palindrome Number)【python】
最新推荐文章于 2024-01-13 15:18:55 发布