当前位置:网站首页>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
边栏推荐
- Hundreds of lines of code to implement a JSON parser
- Folding and sinking sand -- weekly record of ETF
- Convert binary search tree into cumulative tree (reverse middle order traversal)
- Mobilenet series (5): use pytorch to build mobilenetv3 and learn and train based on migration
- Spark SQL空值Null,NaN判断和处理
- 《强化学习周刊》第52期:Depth-CUPRL、DistSPECTRL & Double Deep Q-Network
- After Luke zettlemoyer, head of meta AI Seattle research | trillion parameters, will the large model continue to grow?
- How to use the flutter framework to develop and run small programs
- cf:C. The Third Problem【关于排列这件事】
- 新手入门深度学习 | 3-6:优化器optimizers
猜你喜欢
vSphere实现虚拟机迁移
The inconsistency between the versions of dynamic library and static library will lead to bugs
Meta AI西雅图研究负责人Luke Zettlemoyer | 万亿参数后,大模型会持续增长吗?
Spark AQE
MIT博士论文 | 使用神经符号学习的鲁棒可靠智能系统
Cannot resolve symbol error
测试/开发程序员的成长路线,全局思考问题的问题......
Set data real-time update during MDK debug
SAP Spartacus home 页面读取 product 数据的请求的 population 逻辑
Intensive learning weekly, issue 52: depth cuprl, distspectrl & double deep q-network
随机推荐
The relationship between FPGA internal hardware structure and code
Browser reflow and redraw
Cglib dynamic agent -- example / principle
cf:H. Maximal AND【位运算练习 + k次操作 + 最大And】
MIT doctoral thesis | robust and reliable intelligent system using neural symbol learning
Common API classes and exception systems
从 1.5 开始搭建一个微服务框架——调用链追踪 traceId
curlpost-php
视频直播源码,实现本地存储搜索历史记录
golang mqtt/stomp/nats/amqp
ADS-NPU芯片架构设计的五大挑战
看抖音直播Beyond演唱会有感
Spark-SQL UDF函数
Dede collection plug-in free collection release push plug-in
Distributed base theory
Live video source code, realize local storage of search history
devkit入门
FFT 学习笔记(自认为详细)
Comment faire votre propre robot
KDD 2022 | 脑电AI助力癫痫疾病诊断