Python算法获取最长不重复子串

def getString(aString):
    restult = ''
    substr = ''
    for i in range(len(aString)):
        if aString[i] in substr:
            if len(substr) > len(restult):
                restult = substr
            substr = substr[substr.index(aString[i])+1:]
        else:
            substr+=aString[i]
    return substr if len(substr) > len(restult) else restult

getString("absddfedfiab")
>>> getString("absddfedfiab")
'ediab'

 

posted @ 2021-04-04 13:11  船长博客  阅读(245)  评论(0编辑  收藏  举报
永远相信美好的事情即将发生!