Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Long Non Repeat by zgub4
def non_repeat(line):
if not line:
return ""
all_substr = list()
new_substr = ""
for i in range(0, len(line)):
for c in range(i, len(line)):
if not line[c] in new_substr:
new_substr += line[c]
else:
all_substr.append(new_substr)
new_substr = ""
break
all_substr.append(new_substr)
max = 0
for substr in all_substr:
if len(substr) > max:
max = len(substr)
for substr in all_substr:
if len(substr) == max:
return substr
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"
assert non_repeat('wq') == 'wq', "Fourth"
print('"Run" is good. How is "Check"?')
Oct. 22, 2017