1 import sys
 2 class Solution:
 3     def maxNumberOfBalloons(self, text: str) -> int:
 4         dic = {'b':0,'a':0,'l':0,'o':0,'n':0}
 5         for t in text:
 6             if t in dic:
 7                 dic[t] += 1
 8         r = sys.maxsize
 9         r = min(r,dic['b'])
10         r = min(r,dic['a'])
11         r = min(r,dic['l'] // 2)
12         r = min(r,dic['o'] // 2)
13         r = min(r,dic['n'])
14         return r

算法思想:贪心+Hash。

记录b a l o n出现的次数,计算可以构成的单词的最少字符。

posted on 2019-09-15 21:36  Sempron2800+  阅读(213)  评论(0编辑  收藏  举报