-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1189.cpp
More file actions
35 lines (29 loc) · 752 Bytes
/
Copy path1189.cpp
File metadata and controls
35 lines (29 loc) · 752 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Maximum Number of Balloons
// EASY
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
int maxNumberOfBalloons(string text) {
unordered_map<char, int> mp;
for (const char c : text) {
if (isBalloon(c)) {
mp[c] ++;
}
}
if (mp.size() < 5) return 0;
int minCount = INT_MAX;
for (const auto& [x, y] : mp) {
if (x == 'l' || x == 'o') {
minCount = min(minCount, y / 2);
} else {
minCount = min(minCount, y);
}
}
return minCount;
}
private:
bool isBalloon(char c) {
return c == 'a' || c == 'b' || c == 'l' || c == 'n' || c == 'o';
}
};