close

題目:

Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible.

You can use each character in text at most once. Return the maximum number of instances that can be formed.

簡易版本:

檢視輸入字串可以形成幾個完整ballon

解題想法:

檢視ballon字數,l除二取最小即可

code:

class Solution:
    def maxNumberOfBalloons(self, text: str) -> int:
        return min(text.count("b"),text.count("a"),text.count("l")//2,text.count("o")//2,text.count("n"))

arrow
arrow
    文章標籤
    python leetcode 1189
    全站熱搜

    低階ㄇㄋ 發表在 痞客邦 留言(0) 人氣()