Skip to content

Instantly share code, notes, and snippets.

@rdtr
Created December 22, 2015 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdtr/eae23c2d7d18cc6dc190 to your computer and use it in GitHub Desktop.
Save rdtr/eae23c2d7d18cc6dc190 to your computer and use it in GitHub Desktop.
algorithm_math_palindrome_number.py
class Solution(object):
def isPalindrome(self, x):
"""
:type x: int
:rtype: bool
"""
if x < 0: return False
elif x >= 0 and x < 10: return True
originalX = x
reversedX = 0
while x > 0:
reversedX = reversedX * 10 + x % 10
x /= 10
return originalX == reversedX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment