Longest common substring: Difference between revisions

m
Line 987:
=={{header|PowerShell}}==
 
<lang PowerShell>function lcs([String]$xsis,[String]$ysjs) {
 
if ($xsis.Length -lt $ysjs.Length) {$ysjs,$xsis = $xsis,$ysjs}
$is = $xs.ToCharArray()
$js = $ys.ToCharArray()
$iMax = $sizeMax
for ($k = 0; $k -lt $js.CountLength; ++$k) {
$i,$j = 0,$k
$continue = ($i -lt $is.CountLength) -and ($j -lt $js.CountLength)
while ($continue) {
while ($continue) {
if ($xs[is.Chars($i]) -eq $ys[js.Chars($j])) {break}
++$i
++$j
$continue = ($i -lt $is.CountLength) -and ($j -lt $js.CountLength)
}
$p, $size = $i, 0
while ($continue) {
if ($xs[is.Chars($i]) -ne $ys[js.Chars($j])) {break}
++$size
++$i
++$j
$continue = ($i -lt $is.CountLength) -and ($j -lt $js.CountLength)
}
if ($sizeMax -lt $size) {
Line 1,015 ⟶ 1,014:
}
}
return $xsis.Substring($iMax,$sizeMax)
}
 
678

edits