简单题,主要是问题思路
class Solution {
public:
int maxNumberOfBalloons(string text) {
int b_num=0; //1
int a_num=0; //1
int l_num=0; //2
int o_num=0; //2
int n_num=0; //1
for (int i=0;i<text.size();i++){
if (text[i]=='b'){b_num++;}
if (text[i]=='a'){a_num++;}
if (text[i]=='l'){l_num++;}
if (text[i]=='o'){o_num++;}
if (text[i]=='n'){n_num++;}
}
// find min number
int min = b_num;
if (a_num<min){min=a_num;}
if (l_num/2<min){min=l_num/2;}
if (o_num/2<min){min=o_num/2;}
if (n_num<min){min=n_num;}
return min;
}
};