当前位置:网站首页>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
边栏推荐
- 美国科技行业结束黄金时代,芯片求售、裁员3万等哀声不断
- It's not my boast. You haven't used this fairy idea plug-in!
- Yyds dry inventory run kubeedge official example_ Counter demo counter
- NPM run dev start project error document is not defined
- Shake Sound poussera l'application indépendante de plantation d'herbe "louable", les octets ne peuvent pas oublier le petit livre rouge?
- 039. (2.8) thoughts in the ward
- In JS, string and array are converted to each other (I) -- the method of converting string into array
- 红杉中国,刚刚募资90亿美元
- 华为在多个行业同时出击,吓人的技术让欧美企业瑟瑟发抖
- 在Pi和Jetson nano上运行深度网络,程序被Killed
猜你喜欢
uni-app App端半屏连续扫码
What can one line of code do?
[Li Kou brushing questions] one dimensional dynamic planning record (53 change exchanges, 300 longest increasing subsequence, 53 largest subarray and)
1292_ Implementation analysis of vtask resume() and xtask resume fromisr() in freeros
Happy sound 2[sing.2]
袁小林:安全不只是标准,更是沃尔沃不变的信仰和追求
Quick news: the flybook players' conference is held online; Wechat payment launched "education and training service toolbox"
美国科技行业结束黄金时代,芯片求售、裁员3万等哀声不断
After working for 5 years, this experience is left when you reach P7. You have helped your friends get 10 offers
Tiktok will push the independent grass planting app "praiseworthy". Can't bytes forget the little red book?
随机推荐
【滑动窗口】第九届蓝桥杯省赛B组:日志统计
[Li Kou brush questions] 32 Longest valid bracket
Search map website [quadratic] [for search map, search fan, search book]
红杉中国,刚刚募资90亿美元
document. Usage of write () - write text - modify style and position control
Is this the feeling of being spoiled by bytes?
Sql: stored procedures and triggers - Notes
Proxy and reverse proxy
In JS, string and array are converted to each other (II) -- the method of converting array into string
Summary of cross partition scheme
b站视频链接快速获取
中国白酒的5场大战
一行代码可以做些什么?
JS according to the Chinese Alphabet (province) or according to the English alphabet - Za sort &az sort
C语言:#if、#def和#ifndef综合应用
Nodejs tutorial let's create your first expressjs application with typescript
50 commonly used numpy function explanations, parameters and usage examples
PostgreSQL install GIS plug-in create extension PostGIS_ topology
Ravendb starts -- document metadata
Redistemplate common collection instructions opsforset (V)