9. Palindrome Number
不用convert to string
的话就只能对digit操作了。
class Solution:
def isPalindrome(self, x: int) -> bool:
if x<0: return False
digits = []
while x:
digits.append(x%10)
x //= 10
i, j = 0, len(digits)-1
while i < j:
if digits[i] != digits[j]:
return False
i += 1
j -= 1
return True
Last updated
Was this helpful?