Skip to content

Commit

Permalink
Optimized algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshyPHP committed Nov 3, 2019
1 parent 9f9f558 commit c83c49a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
}
},
"extra": {
"version": "2.0.0"
"version": "2.0.1"
}
}
6 changes: 4 additions & 2 deletions src/ShortestCommonSuperstring.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ public function getShortest(array $strings): string
$this->sortStrings();
$this->removeEmptyStrings();
$this->removeFullyOverlappingStrings();
if (count($this->strings) > 1)
if (isset($this->strings[1]))
{
$this->len = strlen($this->strings[0]);
// Start with the longest partial match possible, which is equal to the length of the
// second longest string minus 1
$this->len = strlen($this->strings[1]);
while (--$this->len > 0)
{
$this->mergeStrings();
Expand Down

0 comments on commit c83c49a

Please sign in to comment.