주어진 문자열 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