Created
March 11, 2020 01:19
-
-
Save heronyang/ae67b1ed35f791a3fdf3ccbddff4cdb2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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