1189. Maximum Number of Balloons

Doyeon Kim·2022년 11월 18일

코딩테스트 공부

목록 보기
141/171

주어진 문자열 text안에 'balloon'이라는 단어를 얼마나 만들 수 있는지 반환하는 문제이다.

일단 text의 문자열과 'balloon'안에 있는 각 글자수를 세고

최소한 (b 1개, a 한개, L 2개, o 두개 n 1개)가 필요하기 때문에 나누어 구한다.

class Solution:
    def maxNumberOfBalloons(self, text: str) -> int:
        textCounter = Counter(text)
        ballonCounter = Counter("balloon")
        
        res = len(text) 

        for i in ballonCounter:
            res = min(res,textCounter[i]//ballonCounter[i])
        return res
profile
성장하고 도전하는 개발자. 프로그래밍 좋아하세요?

0개의 댓글