-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
46 lines (42 loc) · 1.1 KB
/
main.cpp
File metadata and controls
46 lines (42 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
vector<string> wordSubsets(vector<string>& words1, vector<string>& words2)
{
vector<int> total_occurrences(26, 0);
vector<string> answer;
answer.reserve((int)words1.size());
for (string& word: words2)
{
vector<int> occurrences(26, 0);
for (char c: word)
occurrences[c - 'a']++;
for (int i = 0; i < 26; ++i)
total_occurrences[i] = max(occurrences[i], total_occurrences[i]);
}
for (string& word: words1)
{
vector<int> occurrences(26, 0);
for (char c: word)
occurrences[c - 'a']++;
bool accept = true;
for (int i = 0; i < 26; ++i)
{
if (occurrences[i] < total_occurrences[i])
{
accept = false;
break;
}
}
if (accept)
answer.push_back(word);
}
return answer;
}
};
int main()
{
return 0;
}