Skip to content

Commit dfa3459

Browse files
committed
Add 1189 link & javadev's solution
1 parent d984eb0 commit dfa3459

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ I'm currently working on [Analytics-Zoo](https://github.com/intel-analytics/anal
227227
| 1064 | [Fixed Point](https://leetcode.com/problems/fixed-point/) &hearts; | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/1064_Fixed_Point.py) [Java](https://github.com/qiyuangong/leetcode/blob/master/java/1064_Fixed_Point.java) | 1. Go through index and value, until find solution encounter index < value, O(n) and O(1)<br>2. Binary search, O(logn) and O(1) |
228228
| 1089 | [Duplicate Zeros](https://leetcode.com/problems/duplicate-zeros/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/1089_Duplicate_Zeros.py) [Java](https://github.com/qiyuangong/leetcode/blob/master/java/1089_Duplicate_Zeros.java) | 2 Pass, store last position and final move steps, O(n) and O(1) |
229229
| 1108 | [Defanging an IP Address](https://leetcode.com/problems/defanging-an-ip-address/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/1108_Defanging_an_IP_Address.py) [Java](https://github.com/qiyuangong/leetcode/blob/master/java/1108_Defanging_an_IP_Address.java) | String manipulate (split, replace and join), O(n) and O(n) |
230+
| 1189 | [Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons/) | [Java](https://github.com/qiyuangong/leetcode/blob/master/java/1189_Maximum_Number_of_Balloons.java) | Count letters in `balon`, then find min, O(n) and O(1) |
230231
| 1260 | [Shift 2D Grid](https://leetcode.com/problems/shift-2d-grid/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/1260_Shift_2D_Grid.py) [Java](https://github.com/qiyuangong/leetcode/blob/master/java/1260_Shift_2D_Grid.java) | Final position of each element can be computed according to k, m and n, e.g., k == mn, then don't move, O(mn) and O(mn) |
231232
| 1290 | [Convert Binary Number in a Linked List to Integer](https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/1290_Convert_Binary_Number_in_a_Linked_List_to_Integer.py) | Take 2 to the power digit position from right (starting from 0) and multiply it with the digit |
232233
| 1304 | [Find N Unique Integers Sum up to Zero](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/1304_Find_N_Unique_Integers_Sum_up_to_Zero.py) [Java](https://github.com/qiyuangong/leetcode/blob/master/java/1304_Find_N_Unique_Integers_Sum_up_to_Zero.java) | [1,n-1] and its negative sum |
Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
class Solution {
22
public int maxNumberOfBalloons(String text) {
33
HashMap<Character, Integer> map = new HashMap<>();
4-
4+
55
for (char ch : text.toCharArray()) {
66
map.put(ch, map.getOrDefault(ch, 0) + 1);
77
}
8-
8+
99
int res = Integer.MAX_VALUE;
10-
10+
1111
res = Math.min(res, map.getOrDefault('b', 0));
1212
res = Math.min(res, map.getOrDefault('a', 0));
1313
res = Math.min(res, map.getOrDefault('n', 0));
1414
res = Math.min(res, map.getOrDefault('l', 0) / 2);
1515
res = Math.min(res, map.getOrDefault('o', 0) / 2);
16-
16+
1717
return res;
1818
}
19+
20+
/*
21+
// by @javadev
22+
public int maxNumberOfBalloons(String text) {
23+
int[] counts = new int[26];
24+
for (char c : text.toCharArray()) {
25+
counts[c - 'a']++;
26+
}
27+
return Math.min(
28+
counts[0],
29+
Math.min(
30+
counts[1], Math.min(counts[11] / 2, Math.min(counts[14] / 2, counts[13]))));
31+
}*/
1932
}

0 commit comments

Comments
 (0)