Skip to content

Commit f91b2a3

Browse files
authored
Create 1002. Find Common Characters
1 parent e128740 commit f91b2a3

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

1002. Find Common Characters

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution {
2+
public:
3+
vector<string> commonChars(vector<string>& words) {
4+
array<char, 26> freq, minFreq;
5+
minFreq.fill(100);
6+
for(auto& w: words){
7+
freq.fill(0);
8+
for(char c: w) freq[c-'a']++;
9+
for(int i=0; i<26; i++)
10+
minFreq[i]=min(freq[i], minFreq[i]);
11+
}
12+
vector<string> ans;
13+
for(int i=0; i<26; i++){
14+
for(int j=0; j<minFreq[i]; j++)
15+
ans.push_back(string(1, i+'a'));
16+
}
17+
return ans;
18+
}
19+
};
20+
21+
22+
23+
auto init = []() {
24+
ios::sync_with_stdio(false);
25+
cin.tie(nullptr);
26+
cout.tie(nullptr);
27+
return 'c';
28+
}();

0 commit comments

Comments
 (0)