@TOC

# # 题目描述

``````输入：croakOfFrogs = "croakcroak"

``````

``````输入：croakOfFrogs = "crcoakroak"

``````

``````输入：croakOfFrogs = "croakcrook"

``````

``````输入：croakOfFrogs = "croakcroa"

``````

1. `1 <= croakOfFrogs.length <= 10^5`
2. 字符串中的字符只有 'c', 'r', 'o', 'a' 或者 'k'

# # 解题方法

## # 字典

``````输入： "croakcroak"

c
Counter({'c': 1})
r
Counter({'r': 1, 'c': 0})
o
Counter({'o': 1, 'c': 0, 'r': 0})
a
Counter({'a': 1, 'c': 0, 'r': 0, 'o': 0})
k
Counter({'c': 0, 'r': 0, 'o': 0, 'a': 0})
c
Counter({'c': 1, 'r': 0, 'o': 0, 'a': 0})
r
Counter({'r': 1, 'c': 0, 'o': 0, 'a': 0})
o
Counter({'o': 1, 'c': 0, 'r': 0, 'a': 0})
a
Counter({'a': 1, 'c': 0, 'r': 0, 'o': 0})
k
Counter({'c': 0, 'r': 0, 'o': 0, 'a': 0})
``````

Python代码如下：

``````class Solution:
def minNumberOfFrogs(self, croakOfFrogs: str) -> int:
count = collections.Counter()
prev = {"k" :  "a", "a": "o", "o": "r", "r" : "c"}
res = 0
for c in croakOfFrogs:
if c == "c":
count[c] += 1
else:
if count[prev[c]] > 0:
if c != "k":
count[c] += 1
count[prev[c]] -= 1
else:
return -1
res = max(res, sum(count.values()))
return res if sum(count.values()) == 0 else -1
``````

# # 日期

2020 年 4 月 19 日 —— 近期比赛太多