Leetcode 1524 Solution
This article provides solution to leetcode question 1524 (string-matching-in-an-array)
Access this page by simply typing in "lcs 1524" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/string-matching-in-an-array
Solution
class Solution:
def stringMatching(self, words: List[str]) -> List[str]:
words.sort(key=lambda word: len(word))
ans = []
for i, word in enumerate(words):
for j in range(i + 1, len(words)):
if word in words[j]:
ans.append(word)
break
return ans