Skip to content

Instantly share code, notes, and snippets.

@heronyang
Created March 11, 2020 01:19
Show Gist options
  • Save heronyang/ae67b1ed35f791a3fdf3ccbddff4cdb2 to your computer and use it in GitHub Desktop.
Save heronyang/ae67b1ed35f791a3fdf3ccbddff4cdb2 to your computer and use it in GitHub Desktop.
class Solution:
def isPalindrome(self, x: int) -> bool:
if x < 0:
return False
length = math.ceil(math.log10(x))
if length <= 1:
return True
new_x = 0
for _ in range(length//2):
new_x = new_x * 10 + x % 10
x //= 10
if length % 2 == 1:
x //= 10
return x == new_x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment