Anonymous user
Longest substrings without repeating characters: Difference between revisions
Longest substrings without repeating characters (view source)
Revision as of 15:39, 3 June 2021
, 2 years ago→{{header|Phix}}
m (added related tasks.) |
|||
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]]
</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}}==
|