最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

LeetCode 1419. Minimum Number of Frogs Croaking

2023-05-06 12:40 作者:您是打尖兒還是住店呢  | 我要投稿

You are given the string?croakOfFrogs, which represents a combination of the string?"croak"?from different frogs, that is, multiple frogs can croak at the same time, so multiple?"croak"?are mixed.

Return the minimum number of?different?frogs to finish all the croaks in the given string.

A valid?"croak"?means a frog is printing five letters?'c',?'r',?'o',?'a', and?'k'?sequentially. The frogs have to print all five letters to finish a croak. If the given string is not a combination of a valid?"croak"?return?-1.

?

Example 1:

Input: croakOfFrogs = "croakcroak"Output: 1 Explanation: One frog yelling "croak" twice.

Example 2:

Input: croakOfFrogs = "crcoakroak"Output: 2 Explanation: The minimum number of frogs is two. The first frog could yell "crcoakroak". The second frog could yell later "crcoakroak".

Example 3:

Input: croakOfFrogs = "croakcrook"Output: -1Explanation: The given string is an invalid combination of "croak" from different frogs.

?

Constraints:

  • 1 <= croakOfFrogs.length <= 105

  • croakOfFrogs?is either?'c',?'r',?'o',?'a', or?'k'.

都有點(diǎn)快抑郁了,,,

1:判斷是否是按照順序,用hashmap去每次循環(huán)的時(shí)候判斷一下,(這個(gè)地方一直沒(méi)想到)

2:當(dāng)有'c'的時(shí)候 frog++,當(dāng)出現(xiàn)‘k’的時(shí)候 frog--;

3:所以就是要把這2個(gè)問(wèn)題分開(kāi)去處理,一開(kāi)始光想著一下子去處理了。所以走了不少的彎路;

4:最后就是res要max去判斷每個(gè)。

下面是代碼:

都是經(jīng)驗(yàn)教訓(xùn)啊。。。


Runtime93 ms

Beats

6.17%

Memory43.4 MB

Beats

22.14%


LeetCode 1419. Minimum Number of Frogs Croaking的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
涞源县| 玉环县| 永福县| 泰宁县| 前郭尔| 上高县| 车致| 邵武市| 临泽县| 陵川县| 新兴县| 镇安县| 六盘水市| 永宁县| 民勤县| 宿松县| 文水县| 景德镇市| 海丰县| 瓮安县| 山阴县| 瓦房店市| 临清市| 盐边县| 武宣县| 辽阳县| 大宁县| 夏河县| 阿拉善盟| 原平市| 永定县| 普洱| 津市市| 怀来县| 徐州市| 松江区| 茶陵县| 桐梓县| 孝义市| 萝北县| 青岛市|