当前位置:网站首页>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
边栏推荐
- Web开发小妙招:巧用ThreadLocal规避层层传值
- El table table - sortable sorting & disordered sorting when decimal and% appear
- How do I remove duplicates from the list- How to remove duplicates from a list?
- PostgreSQL modifies the password of the database user
- The role of applicationmaster in spark on Yan's cluster mode
- It's not my boast. You haven't used this fairy idea plug-in!
- guava:Collections. The collection created by unmodifiablexxx is not immutable
- R language for text mining Part4 text classification
- Is it profitable to host an Olympic Games?
- FZU 1686 龙之谜 重复覆盖
猜你喜欢
红杉中国,刚刚募资90亿美元
Is this the feeling of being spoiled by bytes?
039. (2.8) thoughts in the ward
【Redis设计与实现】第一部分 :Redis数据结构和对象 总结
Quick news: the flybook players' conference is held online; Wechat payment launched "education and training service toolbox"
jvm:大对象在老年代的分配
Uni app app half screen continuous code scanning
PostgreSQL 修改数据库用户的密码
缓存更新策略概览(Caching Strategies Overview)
50 commonly used numpy function explanations, parameters and usage examples
随机推荐
Description of web function test
One line by line explanation of the source code of anchor free series network yolox (a total of ten articles, you can change the network at will after reading it, if you won't complain to me)
Redistemplate common collection instructions opsforlist (III)
Vim 基本配置和经常使用的命令
Microsoft technology empowerment position - February course Preview
Fastjson parses JSON strings (deserialized to list, map)
Binary tree node at the longest distance
快讯:飞书玩家大会线上举行;微信支付推出“教培服务工具箱”
string的底层实现
mysql根据两个字段去重
El table table - get the row and column you click & the sort of El table and sort change, El table column and sort method & clear sort clearsort
C how to set two columns comboboxcolumn in DataGridView to bind a secondary linkage effect of cascading events
Web开发小妙招:巧用ThreadLocal规避层层传值
PostgreSQL 安装gis插件 CREATE EXTENSION postgis_topology
Explain ESM module and commonjs module in simple terms
抖音將推獨立種草App“可頌”,字節忘不掉小紅書?
Vit paper details
[Li Kou brush questions] 32 Longest valid bracket
R语言做文本挖掘 Part4文本分类
Guava: use of multiset