Created
August 5, 2015 19:31
-
-
Save viveksyngh/f2b5b0705c1cd8c905b9 to your computer and use it in GitHub Desktop.
Determine whether number is palindrome or not
This file contains 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
#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