Longest substrings without repeating characters: Difference between revisions
Content added Content deleted
m (added related tasks.) |
|||
Line 45: | Line 45: | ||
"[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]] |
"[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> |
</pre> |
||
=={{header|Perl}}== |
|||
<lang perl>#!/usr/bin/perl |
|||
use strict; # Longest_substrings_without_repeating_characters |
|||
use warnings; |
|||
for my $string ( qw( xyzyabcybdfd xyzyab zzzzz a thisisastringtest ) ) |
|||
{ |
|||
local $_ = $string; |
|||
my @sub; |
|||
length $+ >= $#sub and ++$sub[length $+]{$+} while s/.*(.)(.*\K\1.*)|(.+)//s; |
|||
printf "%20s -> %s\n", $string, join ' ', sort keys %{ pop @sub }; |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
xyzyabcybdfd -> cybdf zyabc |
|||
xyzyab -> zyab |
|||
zzzzz -> z |
|||
a -> a |
|||
thisisastringtest -> astring ringtes |
|||
</pre> |
|||
=={{header|Phix}}== |
=={{header|Phix}}== |