其他分享
首页 > 其他分享> > LeetCode 1002 查找共用字符

LeetCode 1002 查找共用字符

作者:互联网

题目:

给你一个字符串数组 words ,请你找出所有在 words 的每个字符串中都出现的共用字符( 包括重复字符),并以数组形式返回。你可以按 任意顺序 返回答案。

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/find-common-characters

这题不说了,直接站在dalao的肩膀上,dalao实在是太牛了

链接:力扣

class Solution:
    def commonChars(self, words: List[str]) -> List[str]:
        res =[]
        minchar = min(words, key = len)
        for c in minchar:
            if all(c in word for word in words):
                res.append(c)
                words = [word.replace(c, '', 1) for word in words]
        return res

 

标签:字符,word,res,dalao,1002,查找,words,LeetCode
来源: https://blog.csdn.net/hr159757/article/details/121307763