当前位置:网站首页>Leetcode: maximum number of "balloons"

Leetcode: maximum number of "balloons"

2022-07-07 05:31:00 White speed Dragon King's review

 Insert picture description here
use counter Make a note of

class Solution:
    def maxNumberOfBalloons(self, text: str) -> int:
        cnt = Counter()
        ans = 0x7f7f7f7f
        for c in text:
            cnt[c] += 1
        
        #  Look at each word 
        ans = min(ans, cnt['b'])
        ans = min(ans, cnt['a'])
        ans = min(ans, cnt['n'])
        ans = min(ans, cnt['l'] // 2)
        ans = min(ans, cnt['o'] // 2)

        return ans
原网站

版权声明
本文为[White speed Dragon King's review]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130736512922.html