当前位置:网站首页>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
边栏推荐
- Study diary: February 13, 2022
- 【文件IO的简单实现】
- Fibonacci number
- How to use the flutter framework to develop and run small programs
- Free chat robot API
- The population logic of the request to read product data on the sap Spartacus home page
- ubantu 查看cudnn和cuda的版本
- Folding and sinking sand -- weekly record of ETF
- Dynamic programming -- linear DP
- Programmer growth Chapter 9: precautions in real projects
猜你喜欢

Arduino六足机器人

Mlsys 2020 | fedprox: Federation optimization of heterogeneous networks

ubantu 查看cudnn和cuda的版本

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

BiShe - College Student Association Management System Based on SSM

JVM_ 15_ Concepts related to garbage collection

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

MySQL storage engine
![[groovy] XML serialization (use markupbuilder to generate XML data | set XML tag content | set XML tag attributes)](/img/09/9076de099147b2d0696fe979a68ada.jpg)
[groovy] XML serialization (use markupbuilder to generate XML data | set XML tag content | set XML tag attributes)

程序员搞开源,读什么书最合适?
随机推荐
Arduino hexapod robot
A preliminary study of geojson
Study diary: February 13, 2022
Beginner redis
Mobilenet series (5): use pytorch to build mobilenetv3 and learn and train based on migration
CTF daily question day44 rot
[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
How spark gets columns in dataframe --column, $, column, apply
看抖音直播Beyond演唱会有感
Spark DF增加一列
curlpost-php
Lone brave man
Cve-2017-11882 reappearance
Overview of Zhuhai purification laboratory construction details
KDD 2022 | EEG AI helps diagnose epilepsy
Illustrated network: the principle behind TCP three-time handshake, why can't two-time handshake?
NLP basic task word segmentation third party Library: ICTCLAS [the third party library with the highest accuracy of Chinese word segmentation] [Chinese Academy of Sciences] [charge]
在产业互联网时代,将会凭借大的产业范畴,实现足够多的发展
logstash清除sincedb_path上传记录,重传日志数据