Maximum Number of Balloons LeetCode solution in C++

1
class Solution {
2
public:
3
int maxNumberOfBalloons(string text) {
4
map<char, int> m;
5
for (int i = 0; i < text.length(); i++) {
6
m[text[i]]++;
7
}
8
string s = "balloon";
9
int flag = 1;
10
int c = 0;
11
while (1) {
12
for (int i = 0; i < s.length(); i++) {
13
m[s[i]]--;
14
if (m[s[i]] == -1) {
15
flag = 0;
16
}
17
}
18
if (flag == 0) break;
19
c++;
20
}
21
return c;
22
}
23
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0