Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
My "long non repeat" solution in Clear category for Long Non Repeat by Phil15
def non_repeat(line):
"""The longest substring without repeating chars
"""
#Search of only the first repeating char
c = ''
for ch in line:
if line.count(ch)!=1:
#Here, there's a repeating char
c = ch
break
if c=='':
#No repeating char so it's the line.
return line
else:
#We search the first two indexes of c in the line.
i = line.find(c) #First
j = line.find(c,i+1)#Second
#The solution is in line[:j] or in line[i+1:].
return max([non_repeat(line[:j]), non_repeat(line[i+1:])], key = len)
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"?')
March 1, 2018