|
2 | 2 |
|
3 | 3 | 🟠 <font color=#ffb800>Medium</font>  🔖  [`字符串`](/leetcode/outline/tag/string.md) [`计数`](/leetcode/outline/tag/counting.md)  🔗 [`LeetCode`](https://leetcode.com/problems/minimum-number-of-frogs-croaking) |
4 | 4 |
|
5 | | - |
6 | 5 | ## 题目 |
7 | 6 |
|
8 | 7 | You are given the string `croakOfFrogs`, which represents a combination of the |
9 | 8 | string `"croak"` from different frogs, that is, multiple frogs can croak at |
10 | 9 | the same time, so multiple `"croak"` are mixed. |
11 | 10 |
|
12 | | -_Return the minimum number of_ different _frogs to finish all the croaks in |
13 | | -the given string._ |
| 11 | +_Return the minimum number of_ different _frogs to finish all the croaks in the given string._ |
14 | 12 |
|
15 | 13 | A valid `"croak"` means a frog is printing five letters `'c'`, `'r'`, `'o'`, |
16 | 14 | `'a'`, and `'k'` **sequentially**. The frogs have to print all five letters to |
17 | 15 | finish a croak. If the given string is not a combination of a valid `"croak"` |
18 | 16 | return `-1`. |
19 | 17 |
|
20 | | - |
21 | | - |
22 | 18 | **Example 1:** |
23 | 19 |
|
24 | 20 | > Input: croakOfFrogs = "croakcroak" |
25 | | -> |
26 | | -> Output: 1 |
27 | | -> |
| 21 | +> |
| 22 | +> Output: 1 |
| 23 | +> |
28 | 24 | > Explanation: One frog yelling "croak**"** twice. |
29 | 25 |
|
30 | 26 | **Example 2:** |
31 | 27 |
|
32 | 28 | > Input: croakOfFrogs = "crcoakroak" |
33 | | -> |
34 | | -> Output: 2 |
35 | | -> |
36 | | -> Explanation: The minimum number of frogs is two. |
37 | | -> |
| 29 | +> |
| 30 | +> Output: 2 |
| 31 | +> |
| 32 | +> Explanation: The minimum number of frogs is two. |
| 33 | +> |
38 | 34 | > The first frog could yell "**cr** c**oak** roak". |
39 | | -> |
| 35 | +> |
40 | 36 | > The second frog could yell later "cr**c** oak**roak** ". |
41 | 37 |
|
42 | 38 | **Example 3:** |
43 | 39 |
|
44 | 40 | > Input: croakOfFrogs = "croakcrook" |
45 | | -> |
| 41 | +> |
46 | 42 | > Output: -1 |
47 | | -> |
| 43 | +> |
48 | 44 | > Explanation: The given string is an invalid combination of "croak**"** from different frogs. |
49 | 45 |
|
50 | 46 | **Constraints:** |
51 | 47 |
|
52 | | - * `1 <= croakOfFrogs.length <= 10^5` |
53 | | - * `croakOfFrogs` is either `'c'`, `'r'`, `'o'`, `'a'`, or `'k'`. |
54 | | - |
| 48 | +- `1 <= croakOfFrogs.length <= 10^5` |
| 49 | +- `croakOfFrogs` is either `'c'`, `'r'`, `'o'`, `'a'`, or `'k'`. |
55 | 50 |
|
56 | 51 | ## 题目大意 |
57 | 52 |
|
58 | | -给你一个字符串 `croakOfFrogs`,它表示不同青蛙发出的蛙鸣声(字符串 `"croak"` )的组合。由于同一时间可以有多只青蛙呱呱作响,所以 |
59 | | -`croakOfFrogs` 中会混合多个 `“croak”` _。_ |
| 53 | +给你一个字符串 `croakOfFrogs`,它表示不同青蛙发出的蛙鸣声(字符串 `"croak"` )的组合。由于同一时间可以有多只青蛙呱呱作响,所以 `croakOfFrogs` 中会混合多个 `“croak”` |
60 | 54 |
|
61 | 55 | 请你返回模拟字符串中所有蛙鸣所需不同青蛙的最少数目。 |
62 | 56 |
|
63 | | -要想发出蛙鸣 "croak",青蛙必须 **依序** 输出 `‘c’, ’r’, ’o’, ’a’, ’k’` 这 5 |
64 | | -个字母。如果没有输出全部五个字母,那么它就不会发出声音。如果字符串 `croakOfFrogs` 不是由若干有效的 "croak" 字符混合而成,请返回 |
65 | | -`-1` 。 |
66 | | - |
67 | | - |
| 57 | +要想发出蛙鸣 "croak",青蛙必须 **依序** 输出 `‘c’, ’r’, ’o’, ’a’, ’k’` 这 5 个字母。如果没有输出全部五个字母,那么它就不会发出声音。如果字符串 `croakOfFrogs` 不是由若干有效的 "croak" 字符混合而成,请返回 `-1` 。 |
68 | 58 |
|
69 | 59 | **示例 1:** |
70 | 60 |
|
71 | | -> |
72 | | -> |
73 | | -> |
74 | | -> |
75 | | -> |
76 | 61 | > **输入:** croakOfFrogs = "croakcroak" |
77 | | -> |
78 | | -> **输出:** 1 |
79 | | -> |
| 62 | +> |
| 63 | +> **输出:** 1 |
| 64 | +> |
80 | 65 | > **解释:** 一只青蛙 “呱呱” 两次 |
81 | | -> |
82 | | -> |
83 | 66 |
|
84 | 67 | **示例 2:** |
85 | 68 |
|
86 | | -> |
87 | | -> |
88 | | -> |
89 | | -> |
90 | | -> |
91 | 69 | > **输入:** croakOfFrogs = "crcoakroak" |
92 | | -> |
93 | | -> **输出:** 2 |
94 | | -> |
| 70 | +> |
| 71 | +> **输出:** 2 |
| 72 | +> |
95 | 73 | > **解释:** 最少需要两只青蛙,“呱呱” 声用黑体标注 |
96 | | -> |
| 74 | +> |
97 | 75 | > 第一只青蛙 "**cr** c**oak** roak" |
98 | | -> |
| 76 | +> |
99 | 77 | > 第二只青蛙 "cr**c** oak**roak** " |
100 | | -> |
101 | | -> |
102 | 78 |
|
103 | 79 | **示例 3:** |
104 | 80 |
|
105 | | -> |
106 | | -> |
107 | | -> |
108 | | -> |
109 | | -> |
110 | 81 | > **输入:** croakOfFrogs = "croakcrook" |
111 | | -> |
| 82 | +> |
112 | 83 | > **输出:** -1 |
113 | | -> |
114 | | -> **解释:** 给出的字符串不是 "croak**"** 的有效组合。 |
115 | | -> |
116 | | -> |
117 | | -
|
118 | | - |
| 84 | +> |
| 85 | +> **解释:** 给出的字符串不是 **"croak"** 的有效组合。 |
119 | 86 |
|
120 | 87 | **提示:** |
121 | 88 |
|
122 | | - * `1 <= croakOfFrogs.length <= 10^5` |
123 | | - * 字符串中的字符只有 `'c'`, `'r'`, `'o'`, `'a'` 或者 `'k'` |
124 | | - |
| 89 | +- `1 <= croakOfFrogs.length <= 10^5` |
| 90 | +- 字符串中的字符只有 `'c'`, `'r'`, `'o'`, `'a'` 或者 `'k'` |
125 | 91 |
|
126 | 92 | ## 解题思路 |
127 | 93 |
|
|
0 commit comments