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'

 

上一篇:面试题 01.09. 字符串轮转


下一篇:Django——基于类的视图源码分析 二