难度:简单
给你一个字符串 text,你需要使用 text 中的字母来拼凑尽可能多的单词 "balloon"(气球)。
字符串 text 中的每个字母最多只能被使用一次。请你返回最多可以拼凑出多少个单词 "balloon"。
示例 1:
输入:text = "nlaebolko" 输出:1示例 2:
输入:text = "loonbalxballpoon" 输出:2示例 3:
输入:text = "leetcode" 输出:0提示:
1 <= text.length <= 10^4text全部由小写英文字母组成题解:
class Solution: def maxNumberOfBalloons(self, text: str) -> int: l = {'b':0,'a':0,'l':0,'o':0,'n':0} for i in text: if i in "balloon": l[i] += 1 l['l'] //= 2 l['o'] //= 2 return min(l.values())