当前位置:网站首页>LeetCode:1189. The maximum number of "balloons" -- simple
LeetCode:1189. The maximum number of "balloons" -- simple
2022-07-06 21:44:00 【Kinght_ one hundred and twenty-three】
subject
1189. “ balloon ” Maximum number of
Give you a string text, You need to use text To piece together as many words as possible “balloon”( balloon ).
character string text Each letter in can only be used once at most . Please return the maximum number of words you can piece together “balloon”.
Example 1:
Input :text = “nlaebolko”
Output :1
Example 2:

Input :text = “loonbalxballpoon”
Output :2
Example 3:
Input :text = “leetcode”
Output :0
Tips :
- 1 <= text.length <= 10^4
- text All consist of lowercase English letters
Their thinking
- Statistics .
- One balloon By a b, One a, Two l, Two o, One n.
- So we need to take l and o Number of divided by 2, Then make statistics .
Code
class Solution:
def maxNumberOfBalloons(self, text: str) -> int:
dic = Counter(ch for ch in text if ch in "balloon")
dic['o'] //= 2
dic['l'] //= 2
return min(dic.values()) if len(dic) == 5 else 0
Running results

边栏推荐
- C# 如何在dataGridView里设置两个列comboboxcolumn绑定级联事件的一个二级联动效果
- Dialogue with Jia Yangqing, vice president of Alibaba: pursuing a big model is not a bad thing
- ViT论文详解
- guava:Collections. The collection created by unmodifiablexxx is not immutable
- Is it profitable to host an Olympic Games?
- Comparison between multithreaded CAS and synchronized
- JS according to the Chinese Alphabet (province) or according to the English alphabet - Za sort &az sort
- Sql: stored procedures and triggers - Notes
- 对话阿里巴巴副总裁贾扬清:追求大模型,并不是一件坏事
- 技术分享 | 抓包分析 TCP 协议
猜你喜欢
Why does MySQL index fail? When do I use indexes?

爬虫实战(五):爬豆瓣top250

【Redis设计与实现】第一部分 :Redis数据结构和对象 总结

039. (2.8) thoughts in the ward
![[Digital IC manual tearing code] Verilog automatic beverage machine | topic | principle | design | simulation](/img/75/c0656c4890795bd65874b4f2b16462.jpg)
[Digital IC manual tearing code] Verilog automatic beverage machine | topic | principle | design | simulation

PostgreSQL 修改数据库用户的密码
![[interpretation of the paper] machine learning technology for Cataract Classification / classification](/img/0c/b76e59f092c1b534736132faa76de5.png)
[interpretation of the paper] machine learning technology for Cataract Classification / classification

Quick news: the flybook players' conference is held online; Wechat payment launched "education and training service toolbox"

美国科技行业结束黄金时代,芯片求售、裁员3万等哀声不断

What can one line of code do?
随机推荐
JS learning notes OO create suspicious objects
Dialogue with Jia Yangqing, vice president of Alibaba: pursuing a big model is not a bad thing
启动嵌入式间:资源有限的系统启动
c语言char, wchar_t, char16_t, char32_t和字符集的关系
Seven original sins of embedded development
[Li Kou brushing questions] one dimensional dynamic planning record (53 change exchanges, 300 longest increasing subsequence, 53 largest subarray and)
PostgreSQL install GIS plug-in create extension PostGIS_ topology
Is it profitable to host an Olympic Games?
R语言做文本挖掘 Part4文本分类
Caching strategies overview
mysql根据两个字段去重
麦趣尔砸了小众奶招牌
ROS error: could not find a package configuration file provided by "move_base“
通过数字电视通过宽带网络取代互联网电视机顶盒应用
Binary tree node at the longest distance
[go][reprint]vscode run a HelloWorld example after configuring go
PostgreSQL 修改数据库用户的密码
在Pi和Jetson nano上运行深度网络,程序被Killed
C how to set two columns comboboxcolumn in DataGridView to bind a secondary linkage effect of cascading events
First batch selected! Tencent security tianyufeng control has obtained the business security capability certification of the ICT Institute