class Solution {
public:
string numtostr(int letter)
{
char ch = (char)(letter + 97);
string s = "a";
s[0] = ch;
return s;
}
vector<string> commonChars(vector<string>& words) {
int i,j;
int n = words.size();
vector<vector<int>> v(n);
vector<string> new_string;
for(i = 0;i < n;i++)
{
v[i].resize(26);
}
for(i = 0;i < v.size();i++)
{
for(j = 0;j < v[i].size();j++)
{
v[i][j] = 0;
}
}
for(i = 0;i < words.size();i++)
{
for(j = 0;j < words[i].size();j++)
{
v[i][words[i][j] - 97]++;
}
}
int min;
vector<int> cnt;
cnt.resize(26);
for(j = 0;j < 26;j++)
{
min = v[0][j];
for(i = 1;i < n;i++)
{
if(v[i][j] < min)
{
min = v[i][j];
}
}
if(min > 0)
{
cnt[j] = min;
}
}
for(i = 0;i < 26;i++)
{
for(j = 0;j < cnt[i];j++)
{
new_string.push_back(numtostr(i));
}
}
return new_string;
}
};
07-23
317
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
12-11