把素材string转化为char和其个数对应的dict。遍历balloon,对每个字符在dic中的value-1,直到某个字符的储备=0的时候,返回一共遍历了几次balloon。
class Solution:
def maxNumberOfBalloons(self, text: str) -> int:
dic = collections.Counter(text)
count = 0
res = 0
string = 'balloon'
while True:
for char in string:
if dic[char] != 0:
dic[char] -= 1
else:
return res
res += 1
return res