Jump to content

Longest substrings without repeating characters: Difference between revisions

Added 11l
(Added 11l)
Line 7:
{{Template:Strings}}
<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}}==
Line 55 ⟶ 88:
a > [a]
</pre>
 
 
=={{header|C++}}==
1,481

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.