Skip to content

Commit d537578

Browse files
add 1189
1 parent c840a3e commit d537578

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ _If you like this project, please leave me a star._ ★
2323
|1207|[Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1207.java) | O(n) | O(1) | [:tv:](https://www.youtube.com/watch?v=_NYimlZY1PE)|Easy||
2424
|1200|[Minimum Absolute Difference](https://leetcode.com/problems/minimum-absolute-difference/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1200.java) | || [:tv:](https://www.youtube.com/watch?v=mH1aEjOEjcQ)|Easy||
2525
|1198|[Find Smallest Common Element in All Rows](https://leetcode.com/problems/find-smallest-common-element-in-all-rows/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1198.java) | | | [:tv:](https://www.youtube.com/watch?v=RMiofZrTmWo)|Easy||
26+
|1189|[Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1189.java) | | | |Easy||
2627
|1185|[Day of the Week](https://leetcode.com/problems/day-of-the-week/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1185.java) | | | |Easy||
2728
|1184|[Distance Between Bus Stops](https://leetcode.com/problems/distance-between-bus-stops/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1184.java) | | | [:tv:](https://www.youtube.com/watch?v=RFq7yA5iyhI)|Easy||
2829
|1165|[Single-Row Keyboard](https://leetcode.com/problems/single-row-keyboard/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1165.java) | | | |Easy||
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.fishercoder.solutions;
2+
3+
/**
4+
* 1189. Maximum Number of Balloons
5+
*
6+
* Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible.
7+
* You can use each character in text at most once. Return the maximum number of instances that can be formed.
8+
*
9+
* Example 1:
10+
* Input: text = "nlaebolko"
11+
* Output: 1
12+
*
13+
* Example 2:
14+
* Input: text = "loonbalxballpoon"
15+
* Output: 2
16+
*
17+
* Example 3:
18+
* Input: text = "leetcode"
19+
* Output: 0
20+
*
21+
* Constraints:
22+
* 1 <= text.length <= 10^4
23+
* text consists of lower case English letters only.
24+
* */
25+
public class _1189 {
26+
public static class Solution1 {
27+
public int maxNumberOfBalloons(String text) {
28+
int[] counts = new int[26];
29+
for (char c : text.toCharArray()) {
30+
counts[c - 'a']++;
31+
}
32+
return Math.min(counts[0], Math.min(counts[1], Math.min(counts[11] / 2, Math.min(counts[14] / 2, counts[13]))));
33+
}
34+
}
35+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1189;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static junit.framework.TestCase.assertEquals;
8+
9+
public class _1189Test {
10+
private static _1189.Solution1 solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _1189.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(1, solution1.maxNumberOfBalloons("nlaebolko"));
20+
}
21+
22+
@Test
23+
public void test2() {
24+
assertEquals(2, solution1.maxNumberOfBalloons("loonbalxballpoon"));
25+
}
26+
27+
@Test
28+
public void test3() {
29+
assertEquals(0, solution1.maxNumberOfBalloons("leetcode"));
30+
}
31+
32+
}

0 commit comments

Comments
 (0)