★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ?微信公众号:为敢(WeiGanTechnologies) ?博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/)
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
?微信公众号:为敢(WeiGanTechnologies)
?博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/)
?GitHub地址:https://github.com/strengthen/LeetCode
?原文地址:https://www.cnblogs.com/strengthen/p/11521665.html
?如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
?原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
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^4
text
consists of lower case English letters only.
给你一个字符串 text
,你需要使用 text
中的字母来拼凑尽可能多的单词 "balloon"(气球)。
字符串 text
中的每个字母最多只能被使用一次。请你返回最多可以拼凑出多少个单词 "balloon"。
示例 1:
输入:text = "nlaebolko" 输出:1
示例 2:
输入:text = "loonbalxballpoon" 输出:2
示例 3:
输入:text = "leetcode" 输出:0
提示:
1 <= text.length <= 10^4
text
全部由小写英文字母组成
Runtime: 16 ms Memory Usage: 20.7 MB
1 class Solution { 2 func maxNumberOfBalloons(_ text: String) -> Int { 3 var F:[Character:Int] = [Character:Int]() 4 for c in text 5 { 6 F[c,default:0] += 1 7 } 8 return min(F["b",default:0], F["a",default:0], F["l",default:0]/2, F["o",default:0]/2, F["n",default:0]) 9 } 10 }