题目描述
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.
样例
blablabla
算法1
字典计数
时间复杂度
参考文献
python 3
class Solution(object):
def maxNumberOfBalloons(self, text):
dic = collections.Counter(text)
# print(dic)
return min(dic['b'],dic['a'],dic['l']//2,dic['o']//2,dic['n'])
# return min(dic.get('b',0),dic.get('a',0),dic.get('l',0)//2,dic.get('o',0)//2,dic.get('n',0))