[勇者闯LeetCode] 9. Palindrome Number
Description
Determine whether an integer is a palindrome. Do this without extra space.
Information
- Tags: Math
- Difficulty: Easy
Solution
class Solution(object):
def isPalindrome(self, x):
"""
:type x: int
:rtype: bool
"""
if x < 0 or (x != 0 and x % 10 == 0):
return False
a, b = 0, x
while b > a:
a, b = a * 10 + b % 10, b // 10
return a == b or a // 10 == b