Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit af343c0

Browse files
1189. Maximum Number of Balloons
1 parent a05d183 commit af343c0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

‎maximum-number-of-balloons.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Runtime: 4 ms
2+
// Memory Usage: 8.9 MB
3+
class Solution {
4+
public:
5+
int maxNumberOfBalloons(string text) {
6+
unordered_map<char, int> mp;
7+
for (char c : text) {
8+
if (c == 'b' || c == 'a' || c == 'l' || c == 'o' || c == 'n') {
9+
mp[c]++;
10+
}
11+
}
12+
if (mp.size() != 5) return false;
13+
int res = INT_MAX;
14+
for (auto a : mp) {
15+
res = min(res, (a.first == 'o' || a.first == 'l') ? a.second / 2 : a.second);
16+
}
17+
return res;
18+
19+
}
20+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /