leetcode 1189. “气球” 的最大数量

    技术2022-07-16  72

    1189. “气球” 的最大数量

    难度简单34

    给你一个字符串 text,你需要使用 text 中的字母来拼凑尽可能多的单词 "balloon"(气球)。

    字符串 text 中的每个字母最多只能被使用一次。请你返回最多可以拼凑出多少个单词 "balloon"。

     

    示例 1:

    输入:text = "nlaebolko" 输出:1

    示例 2:

    输入:text = "loonbalxballpoon" 输出:2

    示例 3:

    输入:text = "leetcode" 输出:0

     

    class Solution: def maxNumberOfBalloons(self, text: str) -> int: s='balloon' dic1 = collections.Counter(s) count = 0 dic2 = collections.Counter(text) while (dic2['b']>=1 and dic2['a']>=1 and dic2['l']>=2 and dic2['o']>=2 and dic2['n']>=1): dic2 = dic2-dic1 count+=1 return count

     

    Processed: 0.009, SQL: 9