Longest substrings without repeating characters: Difference between revisions

Content added Content deleted
(Added 11l)
Line 7: Line 7:
{{Template:Strings}}
{{Template:Strings}}
<br><br>
<br><br>

=={{header|11l}}==
{{trans|Python: Some optimisation}}

<lang 11l>F longest_substring2(s)
V max_subs = [s[0.<1]] * 0
V mx = 0
L(x) 0 .< s.len
L(y) x + 1 .. s.len
V sub = s[x .< y]
I y - x >= mx & sub.len == Set(Array(sub)).len
I y - x == mx & sub !C max_subs
max_subs.append(sub)
E
max_subs = [sub]
mx = y - x
R max_subs

L(s) [‘xyzyabcybdfd’, ‘xyzyab’, ‘zzzzz’, ‘a’, ‘’]
print(s‘ => ’longest_substring2(s))

V arr = [1, 2, 3, 4, 1, 2, 5, 6, 1, 7, 8, 1, 0]
print(arr‘ => ’longest_substring2(arr))</lang>

{{out}}
<pre>
xyzyabcybdfd => [zyabc, cybdf]
xyzyab => [zyab]
zzzzz => [z]
a => [a]
=> []
[1, 2, 3, 4, 1, 2, 5, 6, 1, 7, 8, 1, 0] => [[3, 4, 1, 2, 5, 6], [2, 5, 6, 1, 7, 8]]
</pre>


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
Line 55: Line 88:
a > [a]
a > [a]
</pre>
</pre>



=={{header|C++}}==
=={{header|C++}}==