# 1189. Maximum Number of Balloons

Given a string `text`, you want to use the characters of `text` to form as many instances of the word “balloon” as possible.

You can use each character in `text` at most once. Return the maximum number of instances that can be formed.

Example 1:

``````Input: text = "nlaebolko"
Output: 1
``````

Example 2:

``````Input: text = "loonbalxballpoon"
Output: 2
``````

Example 3:

``````Input: text = "leetcode"
Output: 0
``````

``````class Solution {
public:
int maxNumberOfBalloons(string text) {
int res = INT_MAX;
string balloon = "balloon";
unordered_map<char, int> charCnt;
for (char c : text) ++charCnt[c];
for (char c : balloon) {
if (c == 'l' || c == 'o') res = min(res, charCnt[c] / 2);
else res = min(res, charCnt[c]);
}
return res;
}
};
``````

Github 同步地址:

https://github.com/grandyang/leetcode/issues/1189

https://leetcode.com/problems/maximum-number-of-balloons/

https://leetcode.com/problems/maximum-number-of-balloons/discuss/382396/JavaPython-3-Count-solution-w-analysis.