当前位置:网站首页>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

边栏推荐
- 麦趣尔砸了小众奶招牌
- 039. (2.8) thoughts in the ward
- string的底层实现
- Digital transformation takes the lead to resume production and work, and online and offline full integration rebuilds business logic
- High precision face recognition based on insightface, which can directly benchmark hongruan
- Sql: stored procedures and triggers - Notes
- R language for text mining Part4 text classification
- guava:Collections. The collection created by unmodifiablexxx is not immutable
- Redistemplate common collection instructions opsforzset (VI)
- SDL2来源分析7:演出(SDL_RenderPresent())
猜你喜欢

红杉中国,刚刚募资90亿美元

Is it profitable to host an Olympic Games?
Why does MySQL index fail? When do I use indexes?

JS method to stop foreach
![[Li Kou brushing questions] one dimensional dynamic planning record (53 change exchanges, 300 longest increasing subsequence, 53 largest subarray and)](/img/1c/973f824f061d470a4079487d75f0d0.png)
[Li Kou brushing questions] one dimensional dynamic planning record (53 change exchanges, 300 longest increasing subsequence, 53 largest subarray and)

对话阿里巴巴副总裁贾扬清:追求大模型,并不是一件坏事
![[Li Kou brush questions] 32 Longest valid bracket](/img/51/1ce4f9e8517dba214ec82b6567c923.png)
[Li Kou brush questions] 32 Longest valid bracket

PostgreSQL 修改数据库用户的密码

【滑动窗口】第九届蓝桥杯省赛B组:日志统计

PostgreSQL modifies the password of the database user
随机推荐
In JS, string and array are converted to each other (I) -- the method of converting string into array
After working for 5 years, this experience is left when you reach P7. You have helped your friends get 10 offers
Michael smashed the minority milk sign
guava:创建immutableXxx对象的3种方式
Digital transformation takes the lead to resume production and work, and online and offline full integration rebuilds business logic
PostgreSQL modifies the password of the database user
MySQL - transaction details
Redistemplate common collection instructions opsforset (V)
JS method to stop foreach
互联网快讯:吉利正式收购魅族;胰岛素集采在31省全面落地
14年本科毕业,转行软件测试,薪资13.5K
@Detailed differences among getmapping, @postmapping and @requestmapping, with actual combat code (all)
Guava: use of multiset
The underlying implementation of string
【力扣刷题】32. 最长有效括号
Proxy and reverse proxy
1292_ Implementation analysis of vtask resume() and xtask resume fromisr() in freeros
This year, Jianzhi Tencent
Five wars of Chinese Baijiu
美国科技行业结束黄金时代,芯片求售、裁员3万等哀声不断