【leetcode】1189. Maximum Number of Balloons
题目如下:
Given a string
text, you want to use the characters oftextto form as many instances of the word "balloon" as possible.You can use each character in
textat most once. Return the maximum number of instances that can be formed.Example 1:
Input: text = "nlaebolko"
Output: 1Example 2:
Input: text = "loonbalxballpoon"
Output: 2Example 3:
Input: text = "leetcode"
Output: 0Constraints:
1 <= text.length <= 10^4textconsists of lower case English letters only.
解题思路:题目很简单,求出text中b,a,l,o,n这五个字符的出现次数的最小值即可。但有两点需要注意,一是text必须同时包含这五个字符,而是l和o是要算双份。
代码如下:
class Solution(object):
def maxNumberOfBalloons(self, text):
"""
:type text: str
:rtype: int
"""
dic = {}
char_list = ['b','a','l','o','n']
res = float('inf')
for i in text:
if i not in char_list:
continue
dic[i] = dic.setdefault(i,0) + 1
if len(char_list) != len(dic):
return 0
for k,v in dic.iteritems():
if k in ('l','o'):
res = min(res,v/2)
else:
res = min(res,v)
return res
【leetcode】1189. Maximum Number of Balloons的更多相关文章
- 【LeetCode】452. Minimum Number of Arrows to Burst Balloons 解题报告(Python)
[LeetCode]452. Minimum Number of Arrows to Burst Balloons 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https ...
- 【LeetCode】895. Maximum Frequency Stack 解题报告(Python)
[LeetCode]895. Maximum Frequency Stack 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxueming ...
- 【leetcode】998. Maximum Binary Tree II
题目如下: We are given the root node of a maximum tree: a tree where every node has a value greater than ...
- 【LeetCode】375. Guess Number Higher or Lower II 解题报告(Python)
[LeetCode]375. Guess Number Higher or Lower II 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://f ...
- 【LeetCode】718. Maximum Length of Repeated Subarray 解题报告(Python)
[LeetCode]718. Maximum Length of Repeated Subarray 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxu ...
- 【LeetCode】137. Single Number II 解题报告(Python)
[LeetCode]137. Single Number II 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/single- ...
- 【LeetCode】662. Maximum Width of Binary Tree 解题报告(Python)
[LeetCode]662. Maximum Width of Binary Tree 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.co ...
- 【LeetCode】306. Additive Number 解题报告(Python)
[LeetCode]306. Additive Number 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http: ...
- 【POJ2699】The Maximum Number of Strong Kings(网络流)
Description A tournament can be represented by a complete graph in which each vertex denotes a playe ...
随机推荐
- python3实现自动化框架robotframework(最新)
# python3.6及以上版本兼容RIDE1.7.3版本由于最近RIDE1.7.3的版本改进,RIDE这个版本对高版本的wxpython兼容很好,python3.6及以上版本都可以顺利运行RIDE为 ...
- C++写Socket——TCP篇(0)建立连接及双方传输数据
满山的红叶--飘落之时-- 最近接触了点关于用C++写socket的东西,这里总结下. 这里主要是关于TCP的,TCP的特点什么的相关介绍在我另一篇博文里,所以这里直接动手吧. 我们先在windows ...
- nginx优化方案
一.nginx 配置文件中对优化比较有作用的为以下几项:1. worker_processes 8; nginx 进程数,建议按照cpu 数目来指定,一般为它的倍数 (如,2个四核的cpu计为8). ...
- Metinfo5.1 /about/show.php SQL注入
- 【神经网络与深度学习】【CUDA开发】【VS开发】Caffe+VS2013+CUDA7.5+cuDNN配置过程说明
[神经网络与深度学习][CUDA开发][VS开发]Caffe+VS2013+CUDA7.5+cuDNN配置过程说明 标签:[Qt开发] 说明:这个工具在Windows上的配置真的是让我纠结万分,大部分 ...
- Java四类八项基本数据类型
一. 四类八项基本数据类型 1. 整数类型(byte.short.int.long) 三点注意事项: a. Java各整数类型有固定的表示范围和字段长度,其不收操作系统的影响,以保持Java的可移植性 ...
- pair常见用法
pair的使用 关于pair 什么是pair 可以将pair看做一个内部有两个元素的结构体,且两个元素的类型是可以指定的. struct pair{ typename1 first; typename ...
- 链接Caffe,程序报错应用程序无法正常启动(0xc000007b)
目录 背景 Debug 解决办法 原因(猜想) 总结 重点是介绍了一种排查这个问题的方法. 背景 Windows 下, Caffe 单独编译成库并且安装在路径 Caffe_DIR, 动态链接库 Caf ...
- Codeforces 10D LCIS 求最长公共上升子序列及输出这个子序列 dp
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/qq574857122/article/details/34430283 题目链接:点击打开链接 题意 ...
- ES中的查询操作
1.前缀查询 先输入数据: PUT /my_index/address/ { "postcode": "W1 3DG" } PUT /my_index/addr ...