0
点赞
收藏
分享

微信扫一扫

Leetcode 1189. Maximum Number of Balloons [Python]

年夜雪 2022-02-17 阅读 65

把素材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
            
举报

相关推荐

0 条评论