给定一个字符串,找出没有重复字符的最长的子串。
def longest_substr(s):
dic = {}
start,maxlen,substr = 0,0,""
for i,x in enumerate(s):
if x in dic:
start = max(dic[x]+1,start)
dic[x] = i
else:
dic[x] = i
if i-start+1>maxlen:
maxlen = i-start+1
substr = s[start:i+1]
return(substr)
print(longest_substr("abcbefdsafgf"))
print(longest_substr("abdsgcdhef"))
print(longest_substr("abbacsafdefh"))