Skip to content

Commit

Permalink
Reversed the order of the inner loop in removeFullyOverlappingStrings()
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshyPHP committed Dec 22, 2016
1 parent 524a345 commit da4a069
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/ShortestCommonSuperstring.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,13 @@ protected function removeFullyOverlappingStrings()
{
$str = $this->strings[$i];
$len = $strlen[$i];
$j = $i;
while (--$j >= 0)

// Iterate over strings starting with the longest. Stop when we reach strings the size
// of the current string
$j = -1;
while ($strlen[++$j] > $len)
{
if ($strlen[$j] > $len && strpos($this->strings[$j], $str) !== false)
if (strpos($this->strings[$j], $str) !== false)
{
unset($this->strings[$i]);
break;
Expand Down

0 comments on commit da4a069

Please sign in to comment.