Skip to content

Commit 77d2239

Browse files
committed
Time: 67 ms (46.58%) | Memory: 106.9 MB (33.79%) - LeetSync
1 parent ad4118f commit 77d2239

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

952-word-subsets/word-subsets.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
public:
3+
vector<string> wordSubsets(vector<string>& A, vector<string>& B) {
4+
vector<int> count(26), tmp(26);
5+
int i;
6+
for (string b : B) {
7+
tmp = counter(b);
8+
for (i = 0; i < 26; ++i)
9+
count[i] = max(count[i], tmp[i]);
10+
}
11+
vector<string> res;
12+
for (string a : A) {
13+
tmp = counter(a);
14+
for (i = 0; i < 26; ++i)
15+
if (tmp[i] < count[i])
16+
break;
17+
if (i == 26) res.push_back(a);
18+
}
19+
return res;
20+
}
21+
22+
vector<int> counter(string& word) {
23+
vector<int> count(26);
24+
for (char c : word) count[c - 'a']++;
25+
return count;
26+
}
27+
};

0 commit comments

Comments
 (0)