PROBLEM
Determine whether an integer is a palindrome. Do this without extra space.
EXAMPLE
Input:12321
Output:True
题目解析
判断一个数字是否为回文数字,要求不能使用额外的空间。解题思路根据回文数字的特性,前后移动比较至中间,一样即为True,否则为False。我的代码少用了一个判断,所以循环上有冗余。
CODE
class Solution:
def isPalindrome(self, x):
"""
:type x: int
:rtype: bool
"""
for i in range(len(str(x))):
if str(x)[i] != str(x)[-1 - i]:
return False
return True