LeetCode5380。配列内の文字列マッチング

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のような 30,000以上を訪問

おすすめ

転載: blog.csdn.net/weixin_38603360/article/details/105465738