Skip to content

Instantly share code, notes, and snippets.

@sosoyososo
Created September 19, 2013 07:55
Show Gist options
  • Save sosoyososo/6620318 to your computer and use it in GitHub Desktop.
Save sosoyososo/6620318 to your computer and use it in GitHub Desktop.
python:回文数字判断
i = 1281854581821
def getMax(num):
if num < 10:
return num
return getMax(num/10)
def isLastEqualFirst (num) :
if num < 10 :
return YES
return num%10 == getMax(num)
def getNumWhioutFisrt(num):
if num <= 10:
return 0
return num%10 + getNumWhioutFisrt(num/10)*10
def getNumWhioutFirstAndLast(num):
num = getNumWhioutFisrt(num)
return num / 10
def isPalindrome(num):
while num > 10:
if isLastEqualFirst(num):
num = getNumWhioutFirstAndLast(num)
else:
return False
return True
print(isPalindrome(i))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment