当前位置:网站首页>Leetcode daily question solution: 1189 Maximum number of "balloons"
Leetcode daily question solution: 1189 Maximum number of "balloons"
2022-07-06 00:58:00 【Xiaoxinxin's Xiaozhai】
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
Their thinking : Statistics first text in b a l o n The number of these five letters , I borrowed it here python Of Counter function , Then check the dictionary a The length of The length is less than 5 Words It must be impossible to gather enough balon So the output 0 If it is greater than 5 Words Put the l and o Divide the number of two by 2 So I beg b a l o n The minimum value of these five letters can be obtained balloon The minimum value of .
class Solution:
def maxNumberOfBalloons(self, text: str) -> int:
a = Counter(i for i in text if i in "balon") # Calculation text in b a l o n The number of these five letters
if len(a)<5: # If a The length of is less than 5 It means that the length is not enough , Must output as 0
return 0
a["l"]= a["l"] // 2 # Because in balloon in l o Both letters have two So I will l and o Divided by 2
a["o"]= a["o"] // 2
return min(a.values()) # Then seek b a l o n The minimum of these five letters That is, you can get balloon Minimum number of
边栏推荐
- Finding the nearest common ancestor of binary search tree by recursion
- Curlpost PHP
- The detailed page returns to the list and retains the original position of the scroll bar
- [groovy] compile time meta programming (compile time method interception | method interception in myasttransformation visit method)
- 激动人心,2022开放原子全球开源峰会报名火热开启
- Folding and sinking sand -- weekly record of ETF
- Zhuhai laboratory ventilation system construction and installation instructions
- Spark-SQL UDF函数
- Mobilenet series (5): use pytorch to build mobilenetv3 and learn and train based on migration
- Live video source code, realize local storage of search history
猜你喜欢

关于#数据库#的问题:(5)查询库存表中每本书的条码、位置和借阅的读者编号

Illustrated network: the principle behind TCP three-time handshake, why can't two-time handshake?

View class diagram in idea

Spark AQE

Installation and use of esxi
![[groovy] compile time meta programming (AST syntax tree conversion with annotations | define annotations and use groovyasttransformationclass to indicate ast conversion interface | ast conversion inte](/img/61/73becfc3b46669d31b0cf334aa54f2.jpg)
[groovy] compile time meta programming (AST syntax tree conversion with annotations | define annotations and use groovyasttransformationclass to indicate ast conversion interface | ast conversion inte

2020.2.13

测试/开发程序员的成长路线,全局思考问题的问题......

cf:D. Insert a Progression【关于数组中的插入 + 绝对值的性质 + 贪心一头一尾最值】

Daily practice - February 13, 2022
随机推荐
Gartner released the prediction of eight major network security trends from 2022 to 2023. Zero trust is the starting point and regulations cover a wider range
After 95, the CV engineer posted the payroll and made up this. It's really fragrant
Starting from 1.5, build a micro Service Framework - call chain tracking traceid
Fibonacci number
95后CV工程师晒出工资单,狠补了这个,真香...
NLP generation model 2017: Why are those in transformer
Arduino hexapod robot
Cannot resolve symbol error
cf:H. Maximal AND【位运算练习 + k次操作 + 最大And】
Differences between standard library functions and operators
Exciting, 2022 open atom global open source summit registration is hot
Spark SQL UDF function
Convert binary search tree into cumulative tree (reverse middle order traversal)
Getting started with devkit
Gartner发布2022-2023年八大网络安全趋势预测,零信任是起点,法规覆盖更广
Model analysis of establishment time and holding time
可恢复保险丝特性测试
如何制作自己的機器人
Novice entry depth learning | 3-6: optimizer optimizers
Common API classes and exception systems