Skip to content

Commit a81043d

Browse files
Create 1189-Maximum-Number-of-Balloons
1 parent 3cfb9a5 commit a81043d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
class Solution {
2+
public int maxNumberOfBalloons(String text) {
3+
HashMap<Character, Integer> balloon = new HashMap<>();
4+
HashMap<Character, Integer> countText = new HashMap<>();
5+
6+
char[] balloonArray = "balloon".toCharArray();
7+
8+
for (char c : balloonArray) {
9+
if (balloon.containsKey(c)) {
10+
balloon.put(c,balloon.get(c)+1);
11+
} else {
12+
balloon.put(c,1);
13+
}
14+
}
15+
16+
char[] countTextArray = text.toCharArray();
17+
18+
for (char c : countTextArray) {
19+
if (countText.containsKey(c)) {
20+
countText.put(c,countText.get(c)+1);
21+
} else {
22+
countText.put(c,1);
23+
}
24+
}
25+
26+
int res = text.length();
27+
for (Character c : balloon.keySet()) {
28+
res = Math.min(res,countText.getOrDefault(c,0) / balloon.get(c));
29+
}
30+
31+
return res;
32+
}
33+
}

0 commit comments

Comments
 (0)