MCPcopy
hub / github.com/qiyuangong/leetcode / maxNumberOfBalloons

Method maxNumberOfBalloons

java/1189_Maximum_Number_of_Balloons.java:2–18  ·  view source on GitHub ↗
(String text)

Source from the content-addressed store, hash-verified

1class Solution {
2 public int maxNumberOfBalloons(String text) {
3 HashMap<Character, Integer> map = new HashMap<>();
4
5 for (char ch : text.toCharArray()) {
6 map.put(ch, map.getOrDefault(ch, 0) + 1);
7 }
8
9 int res = Integer.MAX_VALUE;
10
11 res = Math.min(res, map.getOrDefault('b', 0));
12 res = Math.min(res, map.getOrDefault('a', 0));
13 res = Math.min(res, map.getOrDefault('n', 0));
14 res = Math.min(res, map.getOrDefault('l', 0) / 2);
15 res = Math.min(res, map.getOrDefault('o', 0) / 2);
16
17 return res;
18 }
19
20 /*
21 // by @javadev

Callers

nothing calls this directly

Calls 1

putMethod · 0.45

Tested by

no test coverage detected