We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e128740 commit f91b2a3Copy full SHA for f91b2a3
1002. Find Common Characters
@@ -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