1002.Find Common Characters
示例 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] 是小写字母Last updated
示例 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] 是小写字母Last updated
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;
}
};