Skip to content

Commit 50ea0aa

Browse files
1189. Maximum Number of Balloons
1 parent 0e2baa1 commit 50ea0aa

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Easy/1189.MaximumNumberofBalloons.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
Given a string text, you want to use the characters of text to form as
3+
many instances of the word "balloon" as possible.
4+
5+
You can use each character in text at most once. Return the maximum
6+
number of instances that can be formed.
7+
8+
Example:
9+
Input: text = "nlaebolko"
10+
Output: 1
11+
12+
Example:
13+
Input: text = "loonbalxballpoon"
14+
Output: 2
15+
16+
Example:
17+
Input: text = "leetcode"
18+
Output: 0
19+
20+
Constraints:
21+
- 1 <= text.length <= 10^4
22+
- text consists of lower case English letters only.
23+
"""
24+
#Difficulty: Easy
25+
#23 / 23 test cases passed.
26+
#Runtime: 32 ms
27+
#Memory Usage: 14.3 MB
28+
29+
#Runtime: 32 ms, faster than 67.90% of Python3 online submissions for Maximum Number of Balloons.
30+
#Memory Usage: 14.3 MB, less than 53.34% of Python3 online submissions for Maximum Number of Balloons.
31+
32+
class Solution:
33+
def maxNumberOfBalloons(self, text: str) -> int:
34+
balloons = float(inf)
35+
for char in 'balon':
36+
if char in 'lo':
37+
balloons = min(balloons, text.count(char) // 2)
38+
else:
39+
balloons = min(balloons, text.count(char))
40+
return balloons

0 commit comments

Comments
 (0)