website/content/ChapterFour/1100~1199/1189.Maximum-Number-of-Balloons.md
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
Constraints:
1 <= text.length <= 10^4text consists of lower case English letters only.给你一个字符串 text,你需要使用 text 中的字母来拼凑尽可能多的单词 "balloon"(气球)。字符串 text 中的每个字母最多只能被使用一次。请你返回最多可以拼凑出多少个单词 "balloon"。
提示:
package leetcode
func maxNumberOfBalloons(text string) int {
fre := make([]int, 26)
for _, t := range text {
fre[t-'a']++
}
// 字符 b 的频次是数组下标 1 对应的元素值
// 字符 a 的频次是数组下标 0 对应的元素值
// 字符 l 的频次是数组下标 11 对应的元素值,这里有 2 个 l,所以元素值需要除以 2
// 字符 o 的频次是数组下标 14 对应的元素值,这里有 2 个 o,所以元素值需要除以 2
// 字符 n 的频次是数组下标 13 对应的元素值
return min(fre[1], min(fre[0], min(fre[11]/2, min(fre[14]/2, fre[13]))))
}