leetpycode/easy/maximum_number_of_ballons.py

21 lines
No EOL
531 B
Python

# https://leetcode.com/problems/maximum-number-of-balloons
class Solution:
def maxNumberOfBalloons(self, text: str) -> int:
b = 0
a = 0
l = 0
o = 0
n = 0
for char in text:
if char == 'b':
b += 1
elif char == 'a':
a += 1
elif char == 'l':
l += 1
elif char == 'o':
o += 1
elif char == 'n':
n += 1
return min(b, a, l // 2, o // 2, n)