1189. “气球” 的最大数量

exiaohu 于 2022-02-13 发布

题目链接:1189. “气球” 的最大数量

计数即可。

from collections import Counter

balloon_counter = {'b': 1, 'a': 1, 'l': 2, 'o': 2, 'n': 1}


class Solution:
    def maxNumberOfBalloons(self, text: str) -> int:
        return min(Counter(text).get(k, 0) // balloon_counter[k] for k in balloon_counter)