Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Long Non Repeat by eugene100372
def non_repeat(line):#Θ(len(line))
L=len(line)
if L<=1:
return line
d={line[0]:0}
start=startmax=0
lmax=1
for i in range(1,L):
if (line[i] in d)and(d[line[i]]>=start):
if i-start>lmax:
lmax=i-start
startmax=start
start=d[line[i]]+1
d[line[i]]=i
if L-start>lmax:
startmax=start
lmax=L-start
return line[startmax:startmax+lmax]
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert non_repeat('aaaaa') == 'a', "First"
assert non_repeat('abdjwawk') == 'abdjw', "Second"
assert non_repeat('abcabcffab') == 'abcf', "Third"
print('"Run" is good. How is "Check"?')
July 31, 2018
Comments: