leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0916.cpp (851B)
0 class Solution {
1 public:
2 vector<string> wordSubsets(const vector<string> &words1, const vector<string> &words2) const {
3 const int n = size(words1), m = size(words2);
4 int count[26] = {0};
5 vector<string> res;
7 for (int i = 0; i < m; i++) {
8 int lcount[27] = {0};
9 for (char c : words2[i])
10 lcount[c - 'a']++;
11 for (int j = 0; j < 26; j++) {
12 count[j] = max(count[j], lcount[j]);
13 }
14 }
16 for (int i = 0; i < n; i++) {
17 int lcount[27] = {0};
18 for (char c : words1[i])
19 lcount[c - 'a']++;
20 for (int k = 0; k < 26; k++) {
21 if (lcount[k] < count[k]) goto next;
22 }
24 res.push_back(words1[i]);
25 next:;
26 }
28 return res;
29 }
30 };