Created
April 13, 2012 03:31
-
-
Save topin27/2373432 to your computer and use it in GitHub Desktop.
计算字符串是否是“回文串”
This file contains hidden or 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
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