当前位置:网站首页>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
边栏推荐
- Introduction to robotics I. spatial transformation (1) posture, transformation
- How to use the flutter framework to develop and run small programs
- Cf:h. maximum and [bit operation practice + K operations + maximum and]
- Building core knowledge points
- Spark SQL UDF function
- Novice entry depth learning | 3-6: optimizer optimizers
- For a deadline, the IT fellow graduated from Tsinghua suddenly died on the toilet
- Cannot resolve symbol error
- 图解网络:TCP三次握手背后的原理,为啥两次握手不可以?
- Recursive method converts ordered array into binary search tree
猜你喜欢

猿桌派第三季开播在即,打开出海浪潮下的开发者新视野

Convert binary search tree into cumulative tree (reverse middle order traversal)

SAP Spartacus home 页面读取 product 数据的请求的 population 逻辑

282. Stone consolidation (interval DP)

Mlsys 2020 | fedprox: Federation optimization of heterogeneous networks

可恢复保险丝特性测试

Starting from 1.5, build a micro Service Framework - call chain tracking traceid

The inconsistency between the versions of dynamic library and static library will lead to bugs

Pbootcms plug-in automatically collects fake original free plug-ins

Exciting, 2022 open atom global open source summit registration is hot
随机推荐
Idea remotely submits spark tasks to the yarn cluster
Gartner发布2022-2023年八大网络安全趋势预测,零信任是起点,法规覆盖更广
Synchronized and reentrantlock
测试/开发程序员的成长路线,全局思考问题的问题......
Daily practice - February 13, 2022
Cf:d. insert a progression [about the insert in the array + the nature of absolute value + greedy top-down]
Idea远程提交spark任务到yarn集群
What is the most suitable book for programmers to engage in open source?
95后CV工程师晒出工资单,狠补了这个,真香...
After 95, the CV engineer posted the payroll and made up this. It's really fragrant
The population logic of the request to read product data on the sap Spartacus home page
Spark AQE
Illustrated network: the principle behind TCP three-time handshake, why can't two-time handshake?
Browser reflow and redraw
DD's command
Exciting, 2022 open atom global open source summit registration is hot
Recursive method to realize the insertion operation in binary search tree
Questions about database: (5) query the barcode, location and reader number of each book in the inventory table
云导DNS和知识科普以及课堂笔记
devkit入门