Skip to content

Instantly share code, notes, and snippets.

@mylons
Created February 25, 2019 13:15
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 mylons/e29cad829791039a08944288720294f7 to your computer and use it in GitHub Desktop.
Save mylons/e29cad829791039a08944288720294f7 to your computer and use it in GitHub Desktop.
from typing import List
def int_to_array(x: int) -> List[int]:
result = []
while x > 0:
tmp = x % 10
result.append(tmp)
x = int((x - tmp) / 10)
return result
class Solution:
def isPalindrome(self, x: int) -> bool:
if x < 0:
return False
arr = int_to_array(x)
end = len(arr) - 1
start = 0
while start < end:
if arr[start] == arr[end]:
start += 1
end -= 1
else:
return False
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment