当前位置:网站首页>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
边栏推荐
- Mobilenet series (5): use pytorch to build mobilenetv3 and learn and train based on migration
- MobileNet系列(5):使用pytorch搭建MobileNetV3并基于迁移学习训练
- curlpost-php
- Distributed base theory
- RAID disk redundancy queue
- MIT博士论文 | 使用神经符号学习的鲁棒可靠智能系统
- After Luke zettlemoyer, head of meta AI Seattle research | trillion parameters, will the large model continue to grow?
- 可恢复保险丝特性测试
- cf:D. Insert a Progression【关于数组中的插入 + 绝对值的性质 + 贪心一头一尾最值】
- Recursive method converts ordered array into binary search tree
猜你喜欢
Extension and application of timestamp
Intensive learning weekly, issue 52: depth cuprl, distspectrl & double deep q-network
Spark SQL空值Null,NaN判断和处理
I'm interested in watching Tiktok live beyond concert
esxi的安装和使用
Convert binary search tree into cumulative tree (reverse middle order traversal)
激动人心,2022开放原子全球开源峰会报名火热开启
猿桌派第三季开播在即,打开出海浪潮下的开发者新视野
Differences between standard library functions and operators
Four dimensional matrix, flip (including mirror image), rotation, world coordinates and local coordinates
随机推荐
[groovy] compile time meta programming (AST syntax tree conversion with annotations | define annotations and use groovyasttransformationclass to indicate ast conversion interface | ast conversion inte
Idea远程提交spark任务到yarn集群
Illustrated network: the principle behind TCP three-time handshake, why can't two-time handshake?
How to extract MP3 audio from MP4 video files?
logstash清除sincedb_path上传记录,重传日志数据
China Taiwan strategy - Chapter 8: digital marketing assisted by China Taiwan
Spark DF增加一列
The inconsistency between the versions of dynamic library and static library will lead to bugs
MYSQL GROUP_ The concat function realizes the content merging of the same ID
curlpost-php
devkit入门
激动人心,2022开放原子全球开源峰会报名火热开启
After 95, the CV engineer posted the payroll and made up this. It's really fragrant
[groovy] compile time meta programming (compile time method interception | method interception in myasttransformation visit method)
The population logic of the request to read product data on the sap Spartacus home page
Convert binary search tree into cumulative tree (reverse middle order traversal)
可恢复保险丝特性测试
Cve-2017-11882 reappearance
Interview must brush algorithm top101 backtracking article top34
How to make your own robot