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 lukasz.bogaczynski
def non_repeat(text):
if(len(text)) < 1:
return ""
longest_non_repeat = []
current_non_repeat = []
stop_pos = 1
current_index = 0
while current_index < len(text):
if text[current_index] not in current_non_repeat:
current_non_repeat.append(text[current_index])
current_index = current_index + 1
else:
if len(current_non_repeat) > len(longest_non_repeat):
longest_non_repeat = current_non_repeat
current_non_repeat = [text[stop_pos]]
current_index = stop_pos + 1
stop_pos = current_index
if len(current_non_repeat) > len(longest_non_repeat):
longest_non_repeat = current_non_repeat
return ''.join(longest_non_repeat)
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"?')
Oct. 21, 2017
Comments: