Skip to content

Commit a6d37e5

Browse files
committed
1189 added
1 parent dad0928 commit a6d37e5

File tree

7 files changed

+124
-35
lines changed

7 files changed

+124
-35
lines changed

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@
196196
"lexicographicaly",
197197
"lleeelee",
198198
"longest",
199+
"loonbalxballpoon",
199200
"lpnpelpwy",
200201
"make",
201202
"map",
@@ -208,6 +209,7 @@
208209
"n",
209210
"nbsp",
210211
"next",
212+
"nlaebolko",
211213
"ntse",
212214
"num",
213215
"numberify",
12.8 KB
Loading
15.7 KB
Loading
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# [1189. Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons/)
2+
3+
Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible.
4+
5+
You can use each character in text at most once. Return the maximum number of instances that can be formed.
6+
7+
Example 1:
8+
9+
![1](1.jpeg)
10+
11+
```text
12+
Input: text = "nlaebolko"
13+
Output: 1
14+
```
15+
16+
Example 2:
17+
18+
![2](2.jpeg)
19+
20+
```text
21+
Input: text = "loonbalxballpoon"
22+
Output: 2
23+
```
24+
25+
Example 3:
26+
27+
```text
28+
Input: text = "leetcode"
29+
Output: 0
30+
```
31+
32+
Constraints:
33+
34+
- `1 <= text.length <= 10^4`
35+
- `text consists of lower case English letters only.`
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package problem1189
2+
3+
func maxNumberOfBalloons(text string) int {
4+
return 0
5+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package problem1189
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
// tcs is testcase slice
10+
var tcs = []struct {
11+
text string
12+
ans int
13+
}{
14+
15+
{
16+
"nlaebolko",
17+
1,
18+
},
19+
20+
{
21+
"loonbalxballpoon",
22+
2,
23+
},
24+
25+
{
26+
"leetcode",
27+
0,
28+
},
29+
30+
// 可以有多个 testcase
31+
}
32+
33+
func Test_maxNumberOfBalloons(t *testing.T) {
34+
a := assert.New(t)
35+
36+
for _, tc := range tcs {
37+
a.Equal(tc.ans, maxNumberOfBalloons(tc.text), "输入:%v", tc)
38+
}
39+
}
40+
41+
func Benchmark_maxNumberOfBalloons(b *testing.B) {
42+
for i := 0; i < b.N; i++ {
43+
for _, tc := range tcs {
44+
maxNumberOfBalloons(tc.text)
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)