You are viewing a single comment's thread. Return to all comments →
Perl:
sub commonChild { my ($s1, $s2) = @_; my $n = length($s1); my $m = length($s2); my @prev = (0) x ($m + 1); my @curr = (0) x ($m + 1); for my $i (1 .. $n) { for my $j (1 .. $m) { if (substr($s1, $i - 1, 1) eq substr($s2, $j - 1, 1)) { $curr[$j] = $prev[$j - 1] + 1; } else { $curr[$j] = $curr[$j - 1] > $prev[$j] ? $curr[$j - 1] : $prev[$j]; } } @prev = @curr; } return $curr[$m]; }
Seems like cookies are disabled on this browser, please enable them to open this website
Common Child
You are viewing a single comment's thread. Return to all comments →
Perl: