[Leetcodepython] 9. Palindrome Number, leetcodepalindrome
# Number of replies
# Method1: Compare the integer transpose with the original number, which is the same as the return number. The negative number is not the return number.
# Overflow does not need to be considered when the integer is reversed here, but it does not mean that if it is a C/C ++ or other language, it does not need to be considered
Class Solution (object ):
Def isPalindrome (self, x ):
"""
: Type x: int
: Rtype: bool
"""
If x <0: return False
# If the negative number is not the number of replies, return False
Xre = x
Ans = 0
While x> 0:
Ans = ans * 10 + x % 10
X = x // 10
If ans> 21474836547:
Ans = 0
Print ans, xre
Return ans = xre
# Method2
Class Solution (object ):
Def isPalindrome (self, x ):
"""
: Type x: int
: Rtype: bool
"""
If x <0: return False
# If the negative number is not the number of replies, return False
Digits = 1
While x/digits> = 10:
Digits * = 10
While digits> 1:
Right = x % 10
Left = x/digits
If left! = Right: return False
X = (x % digits)/10
Digits // = 100
Return True