word-subsets 1.0.0
Word Subsets
Loading...
Searching...
No Matches
Solution Class Reference

Public Member Functions

vector< string > wordSubsets (vector< string > &words1, vector< string > &words2)
 

Detailed Description

Definition at line 5 of file main.cpp.

Member Function Documentation

◆ wordSubsets()

vector< string > Solution::wordSubsets ( vector< string > &  words1,
vector< string > &  words2 
)
inline

Definition at line 8 of file main.cpp.

9 {
10 vector<int> total_occurrences(26, 0);
11 vector<string> answer;
12 answer.reserve((int)words1.size());
13 for (string& word: words2)
14 {
15 vector<int> occurrences(26, 0);
16 for (char c: word)
17 occurrences[c - 'a']++;
18 for (int i = 0; i < 26; ++i)
19 total_occurrences[i] = max(occurrences[i], total_occurrences[i]);
20 }
21 for (string& word: words1)
22 {
23 vector<int> occurrences(26, 0);
24 for (char c: word)
25 occurrences[c - 'a']++;
26 bool accept = true;
27 for (int i = 0; i < 26; ++i)
28 {
29 if (occurrences[i] < total_occurrences[i])
30 {
31 accept = false;
32 break;
33 }
34 }
35 if (accept)
36 answer.push_back(word);
37 }
38 return answer;
39 }

The documentation for this class was generated from the following file: