Skip to content

Instantly share code, notes, and snippets.

@viveksyngh
Created August 5, 2015 19:31
Show Gist options
  • Save viveksyngh/f2b5b0705c1cd8c905b9 to your computer and use it in GitHub Desktop.
Save viveksyngh/f2b5b0705c1cd8c905b9 to your computer and use it in GitHub Desktop.
Determine whether number is palindrome or not
#Determine whether an integer is a palindrome. Do this without extra space.
#A palindrome integer is an integer x for which reverse(x) = x where reverse(x) is x with its digit reversed.
#Negative numbers are not palindromic.
def isPalindrome(self, A):
num = 0
if A < 0 :
return False
temp = A
while temp != 0 :
num = num*10 + (temp%10)
temp = temp/10
return num == abs(A)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment