-
Notifications
You must be signed in to change notification settings - Fork 0
/
925.long-pressed-name.cpp
42 lines (36 loc) · 989 Bytes
/
925.long-pressed-name.cpp
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
class Solution {
public:
vector<string> wordSubsets(vector<string>& A, vector<string>& B) {
vector<string>s;
map<char,int>m1;
int n=0;
for(int i=0;i<B.size();i++){
map<char,int>m2;
for(int j=0;j<B[i].size();j++){
m2[B[i][j]]++;}
for(auto it:m2)
{
m1[it.first]=max(it.second,m1[it.first]);
}
}
n=m1.size();
for(int i=0;i<A.size();i++){
int c=0;
map<char,int>m2;
for(int j=0;j<A[i].size();j++)
{
m2[A[i][j]]++;
}
for(auto it:m1)
{
if(m2[it.first]>=it.second)
c++;
else
break;
}
if(n==c)
s.push_back(A[i]);
}
return s;
}
};