-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path1189.cpp
36 lines (36 loc) · 790 Bytes
/
1189.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
class Solution {
public:
int maxNumberOfBalloons(string text) {
map<char,int> m;
m['b']=0;
m['a']=0;
m['l']=0;
m['o']=0;
m['n']=0;
for(int i=0;i<text.length();i++)
{
char c=text[i];
if(m.find(c)!=m.end())
{
m[c]++;
}
}
int ans=INT_MAX;
for(auto it=m.begin();it!=m.end();it++)
{
int freq;
if(it->first=='o' or it->first=='l')
{
freq=it->second;
freq=freq/2;
ans=min(ans,freq);
}
else
{
freq=it->second;
ans=min(ans,freq);
}
}
return ans;
}
};