首页 > 其他 > 详细

leetcode1408

时间:2020-04-12 14:04:53      阅读:40      评论:0      收藏:0      [点我收藏+]
 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)

 

leetcode1408

原文:https://www.cnblogs.com/asenyang/p/12684683.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!