# 1002.Find Common Characters

**1002.Find Common Characters**

难度:Easy

> 给定仅有小写字母组成的字符串数组 A，返回列表中的每个字符串中都显示的全部字符（包括重复字符）组成的列表。例如，如果一个字符在每个字符串中出现 3 次，但不是 4 次，则需要在最终答案中包含该字符 3 次。

你可以按任意顺序返回答案。

```
示例 1：

输入：["bella","label","roller"]
输出：["e","l","l"]
示例 2：

输入：["cool","lock","cook"]
输出：["c","o"]
 

提示：

1 <= A.length <= 100
1 <= A[i].length <= 100
A[i][j] 是小写字母
```

方法：将每个单词字母用字典存起来，比较出现次数，取出现次数少的保存。

```
class Solution {
public:
    vector<string> commonChars(vector<string>& A) {
        vector<string> res;
        unordered_map<char,int> cnt;

        int len=A.size();
        for(auto c: A[0])
            cnt[c]++;
        for(int i=1;i<len;i++)
        {
            unordered_map<char,int> tmp;
            for(auto c:A[i])
                tmp[c]++ ;
            for(char c='a';c<='z';c++)
               // cout<<cnt[c]<<c<<tmp[c]<<endl;
                cnt[c]=min(tmp[c],cnt[c]);
        }
        for(char c='a';c<='z';c++)
            while(cnt[c]--)
                res.push_back(string(1,c));
        return res;
    }
};
```

> 执行用时 : 84 ms, 在Find Common Characters的C++提交中击败了100.00% 的用户 内存消耗 : 14.1 MB, 在Find Common Characters的C++提交中击败了100.00% 的用户


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dfine.gitbook.io/leetcode/1002.find_common_characters.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
