LeetCode 5380. 数组中的字符串匹配

5380. 数组中的字符串匹配

python 字符串长度排序

class Solution:
    def stringMatching(self, words: List[str]) -> List[str]:
        res = []
        words = sorted(words, key=lambda x: len(x))
        for i, word in enumerate(words):
            for j in range(i+1, len(words)):
                if word in words[j]:
                    res.append(word)
                    break
        return res
发布了248 篇原创文章 · 获赞 29 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/weixin_38603360/article/details/105465738