Skip to content

Instantly share code, notes, and snippets.

@topin27
Created April 13, 2012 03:31
Show Gist options
  • Save topin27/2373432 to your computer and use it in GitHub Desktop.
Save topin27/2373432 to your computer and use it in GitHub Desktop.
计算字符串是否是“回文串”
def foo(s_, i_ = 0):
strLen = len(s_)
if strLen == 0:
return False
if i_ < 0:
return False
if i_ == (strLen / 2 - 1):
return s_[i_] == s_[strLen - 1 - i_]
return (s_[i_] == s_[strLen - 1 - i_] and foo(s_, i_ + 1))
if __name__ == "__main__":
s = 'madam'
print foo(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment