【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^4
textconsists 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 ... 
随机推荐
- <数据结构系列2>栈的实现与应用(LeetCode<有效的的括号>)
			首先想要实现栈,就得知道栈为何物,以下一段摘抄至百度百科: 栈(stack)又名堆栈,它是一种运算受限的线性表.其限制是仅允许在表的一端进行插入和删除运算.这一端被称为栈顶,相对地,把另一端称为栈底. ... 
- 意想不到的JavaScript(每日一题1)
			问题: 答案: 解析: 
- Win10删除右键菜单快捷键方法
			打开注册表,找到HKEY_CLASSES_ROOT\Directory\Background路径,删除对应的快捷方式即可 
- mysql——视图——概念
			二.视图 视图是一种虚拟的表,是从数据库中的一个或者多个表中导出来的表. 视图还可以从已经存在的视图的基础上定义. 数据库中只存放了视图的定义,并没有存放视图中的数据,这些数据存放在原来的表中. 使用 ... 
- mysql——多表——内连接查询
			内连接查询:可以查询两个或者两个以上的表,当两个表中存在表示相同意义的字段时,可以通过该字段来连接这两个表: 当该字段的值相等时,就查询出该记录. 前期准备两个表: ), d_id ), name ) ... 
- CentOS8Linux中配置网易云网络yum源安装软件
			在CentOS8Linux中配置网易云网络yum源安装软件 前提是你的操作系统是CentOS-Linux 你已经配置好了本地yum源,并且你的网络是可用的. 本地yum源配置请参考:https://w ... 
- leveldb Arena
			背景我们都知道,对于一个高性能的服务器端程序来说,内存的使用非常重要.C++提供了new/delete来管理内存的申请和释放,但是对于小对象来说,直接使用new/delete代价比较大,要付出额外的空 ... 
- python中导入模块的注意点
			1.import 和 from import 的区别 import module导入模块:语句执行完后会创建一个新的命名空间,在该命名空间中执行相应的函数.执行时,需要的变量.函数和类名前需要加 ... 
- C++中setiosflags()的用法
			cout<<setiosflags(ios::fixed)<<setiosflags(ios::right)<<setprecision(2); setiosfla ... 
- [BJWC2008] Gate Of Babylon
			题目链接 容斥+隔板法+Lucas定理 #include <bits/stdc++.h> using namespace std; const int N=1e5+10; int n,m, ... 
