1 class Solution:
 2     def stringMatching(self, words: 'List[str]') -> 'List[str]':
 3         n = len(words)
 4         words = sorted(words,key=lambda x:len(x))
 5         res = set()
 6         for i in range(n):
 7             cur = words[i]
 8             for j in range(i+1,n):
 9                 target = words[j]
10                 if target.find(cur) >= 0:
11                     res.add(cur)
12         return list(res)

算法类型:字符串子串判断。

双层循环,时间复杂度O(n^2)

 

posted on 2020-04-12 12:41  Sempron2800+  阅读(176)  评论(0编辑  收藏  举报