File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments