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 croak in the given string.

A valid "croak" means a frog is printing 5 letters ‘c’, ’r’, ’o’, ’a’, ’k’ sequentially. The frogs have to print all five letters to finish a croak. If the given string is not a combination of 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: -1
Explanation: The given string is an invalid combination of "croak" from different frogs.

Example 4:

Input: croakOfFrogs = "croakcroa"
Output: -1

Constraints:

  • 1 <= croakOfFrogs.length <= 10^5
  • All characters in the string are: 'c''r''o''a' or 'k'.

思路:模拟一遍就好了,幸亏croak没有重复的字符。。

class Solution(object):def minNumberOfFrogs(self, croakOfFrogs):""":type croakOfFrogs: str:rtype: int"""d = {}for c in 'croak':d[c] = 0res = 1for c in croakOfFrogs:if c == 'c':d['c'] += 1if max(d.values()) > res:res += 1elif c == 'r':d['r'] += 1if d['r'] > d['c']:return -1elif c == 'o':d['o'] += 1if d['o'] > d['r']:return -1elif c == 'a':d['a'] += 1if d['a'] > d['o']:return -1elif c == 'k':d['k'] += 1if d['k'] > d['a']:return -1for cc in 'croak':d[cc] -= 1return res if max(d.values()) == 0 else -1

1419. Minimum Number of Frogs Croaking相关推荐

  1. 452 Minimum Number of Arrows to Burst Balloons

    452 Minimum Number of Arrows to Burst Balloons 文章目录 452 Minimum Number of Arrows to Burst Balloons 1 ...

  2. codeforce 804B Minimum number of steps

    cf劲啊 原题: We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each ...

  3. LeetCode——1888. 使二进制字符串字符交替的最少反转次数(Minimum Number of Flips to Make the Binary ...)[中等]——分析及代码(Java)

    LeetCode--1888. 使二进制字符串字符交替的最少反转次数[Minimum Number of Flips to Make the Binary String Alternating][中等 ...

  4. 871. Minimum Number of Refueling Stops

    题目: A car travels from a starting position to a destination which is target miles east of the starti ...

  5. LeetCode刷题:871. Minimum Number of Refueling Stops

    LeetCode刷题:871. Minimum Number of Refueling Stops 原题链接:https://leetcode.com/problems/minimum-number- ...

  6. LeetCode 871. Minimum Number of Refueling Stops 最少加油次数

    LeetCode 871. Minimum Number of Refueling Stops 本题是LeetCode 871题,最少加油次数. 题目描述 A car travels from a s ...

  7. LeetCode871.Minimum Number of Refueling Stops

    871.Minimum Number of Refueling Stops(加油站的最小数量) Description Difficulty: hard Example 1: Example 2: E ...

  8. 算法设计与分析:Minimum Number of Refueling Stops(Week 11)

    学号:16340008 题目:871. Minimum Number of Refueling Stops Question: A car travels from a starting positi ...

  9. LeetCode: 871. Minimum Number of Refueling Stops

    LeetCode: 871. Minimum Number of Refueling Stops 题目描述 A car travels from a starting position to a de ...

  10. LeetCode 202次周赛 1553. Minimum Number of Days to Eat N Oranges

    1553. Minimum Number of Days to Eat N Oranges 题目描述 思路分析 弱智动态规划 可行的动态规划 直觉上正确的思路 代码实现 证明正确性 复杂度分析 总结 ...

最新文章

  1. comsol matlab 循环,comsol保存为m文件,怎样在m文件里面加入for循环 - 仿真模拟 - 小木虫 - 学术 科研 互动社区...
  2. 部署项目的问题(一)—— vue工程打包上线样式错乱问题
  3. xbmc电脑版本和手机版本学习教程
  4. 几点减几点怎么列算式_洁净室平面设计怎么做?洁净室施工做到这几点就对了...
  5. 永远不要去依赖别人_感悟人生的经典句子:不要轻易去依赖一个人
  6. php的核心类 控制,phpMVC框架的核心启动类定义
  7. python利器-[python] bluepy 一款python封装的BLE利器
  8. [转载] strtol() -- 将字符串转换成长整型数(转载)
  9. python中list和numpy的array的转换
  10. cenyos7安装 yum不可用_小区阳台隐形网横管不可用扁管,要改再去安装,还有问题...
  11. C/C++[codeup 2043]小白鼠排队
  12. python绘制四边形,三角形图形案例
  13. discuz 模板标签
  14. php 获取文章内容首图,关于文章的首图及图片版权问题
  15. 图形学 Lecture7 光线追踪
  16. 网吧管理系统C语言作业,C语言课程设计-网吧管理系统.doc
  17. S5PV210 iNAND/SD卡
  18. Muse UI遇到的坑
  19. 为什么吃饭的时候不说话
  20. 机器学习之支持向量回归(SVR)——南京审计大学金审学院

热门文章

  1. 什么是霍尔推进器?只能推动一张纸,却成为多国追捧的黑科技
  2. Eclipse-WTP什么意思?
  3. Chromium Embedded Framework (CEF) 介绍
  4. sudo: no valid sudoers sources found, quitting问题解决方案
  5. itunes下载管理appstore老版本app
  6. Elastic:关于索引生命周期ILM的一些试验;warm,cold,delete节点中min_age设置的是增量还是累计值
  7. Python 错误重试库 tenacity retry
  8. SCI论文分区有两种方法
  9. 横版闯关手游【觉醒大陆90装备版】5月最新整理商业Linux手工服务端+吃鸡+组队PK+运营后台+CDK清包后台+GM授权后台+安卓苹果双端+视频教程+详细搭建教程
  10. pycharm更换国内源