当前位置:网站首页>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
边栏推荐
- Dynamic programming -- linear DP
- Mobilenet series (5): use pytorch to build mobilenetv3 and learn and train based on migration
- Daily practice - February 13, 2022
- Model analysis of establishment time and holding time
- Intensive learning weekly, issue 52: depth cuprl, distspectrl & double deep q-network
- Study diary: February 13, 2022
- curlpost-php
- [groovy] XML serialization (use markupbuilder to generate XML data | set XML tag content | set XML tag attributes)
- WordPress collection plug-in automatically collects fake original free plug-ins
- MYSQL GROUP_ The concat function realizes the content merging of the same ID
猜你喜欢

KDD 2022 | 脑电AI助力癫痫疾病诊断

Spark AQE

ADS-NPU芯片架构设计的五大挑战

可恢复保险丝特性测试
![[groovy] JSON serialization (convert class objects to JSON strings | convert using jsonbuilder | convert using jsonoutput | format JSON strings for output)](/img/52/021931181ad3f4bef271b4e98105c2.jpg)
[groovy] JSON serialization (convert class objects to JSON strings | convert using jsonbuilder | convert using jsonoutput | format JSON strings for output)

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

I'm interested in watching Tiktok live beyond concert

《强化学习周刊》第52期:Depth-CUPRL、DistSPECTRL & Double Deep Q-Network

程序员搞开源,读什么书最合适?

vSphere实现虚拟机迁移
随机推荐
Synchronized and reentrantlock
NLP generation model 2017: Why are those in transformer
[groovy] JSON serialization (jsonbuilder builder | generates JSON string with root node name | generates JSON string without root node name)
vSphere实现虚拟机迁移
Cf:d. insert a progression [about the insert in the array + the nature of absolute value + greedy top-down]
Cglib dynamic agent -- example / principle
激动人心,2022开放原子全球开源峰会报名火热开启
小程序容器可以发挥的价值
Cf:h. maximum and [bit operation practice + K operations + maximum and]
[groovy] JSON string deserialization (use jsonslurper to deserialize JSON strings | construct related classes according to the map set)
[groovy] compile time metaprogramming (compile time method interception | find the method to be intercepted in the myasttransformation visit method)
Logstash clear sincedb_ Path upload records and retransmit log data
ADS-NPU芯片架构设计的五大挑战
Natural language processing (NLP) - third party Library (Toolkit):allenlp [library for building various NLP models; based on pytorch]
For a deadline, the IT fellow graduated from Tsinghua suddenly died on the toilet
The inconsistency between the versions of dynamic library and static library will lead to bugs
Cf:c. the third problem
Spark SQL空值Null,NaN判断和处理
Folding and sinking sand -- weekly record of ETF
Spark DF adds a column