1408. String Matching in an Array #1095
-
Topics: Given an array of string A substring is a contiguous sequence of characters within a string Example 1:
Example 2:
Example 3:
Constraints:
Hint:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
We need to find all strings in the Let's implement this solution in PHP: 1408. String Matching in an Array <?php
/**
* @param String[] $words
* @return String[]
*/
function stringMatching($words) {
...
...
...
/**
* go to ./solution.php
*/
}
// Example 1
$words = ["mass", "as", "hero", "superhero"];
print_r(stringMatching($words));
// Example 2
$words = ["leetcode", "et", "code"];
print_r(stringMatching($words));
// Example 3
$words = ["blue", "green", "bu"];
print_r(stringMatching($words));
?> Explanation:
Time Complexity:
Example Outputs:For input Array
(
[0] => as
[1] => hero
) For input Array
(
[0] => et
[1] => code
) For input Array
(
) This solution works well for the given problem constraints. |
Beta Was this translation helpful? Give feedback.
We need to find all strings in the
words
array that are substrings of another word in the array, you can use a brute force approach. The approach involves checking each string in the list and verifying if it's a substring of any other string.Let's implement this solution in PHP: 1408. String Matching in an Array