当前位置:网站首页>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
边栏推荐
- JVM_ 15_ Concepts related to garbage collection
- cf:C. The Third Problem【关于排列这件事】
- NLP text processing: lemma [English] [put the deformation of various types of words into one form] [wet- > go; are- > be]
- Beginner redis
- KDD 2022 | 脑电AI助力癫痫疾病诊断
- MCU通过UART实现OTA在线升级流程
- The inconsistency between the versions of dynamic library and static library will lead to bugs
- NLP generation model 2017: Why are those in transformer
- Introduction of motor
- Cf:c. the third problem
猜你喜欢

Installation and use of esxi

How to extract MP3 audio from MP4 video files?

I'm interested in watching Tiktok live beyond concert

MySQL storage engine

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

Questions about database: (5) query the barcode, location and reader number of each book in the inventory table

Comment faire votre propre robot

MCU通过UART实现OTA在线升级流程

Building core knowledge points

Exciting, 2022 open atom global open source summit registration is hot
随机推荐
How to extract MP3 audio from MP4 video files?
Questions about database: (5) query the barcode, location and reader number of each book in the inventory table
Common API classes and exception systems
Recoverable fuse characteristic test
Recursive method to realize the insertion operation in binary search tree
激动人心,2022开放原子全球开源峰会报名火热开启
Hundreds of lines of code to implement a JSON parser
【文件IO的简单实现】
Dedecms plug-in free SEO plug-in summary
Fibonacci number
Lone brave man
Promise
几百行代码实现一个 JSON 解析器
直播系统代码,自定义软键盘样式:字母、数字、标点三种切换
MYSQL---查询成绩为前5名的学生
curlpost-php
The detailed page returns to the list and retains the original position of the scroll bar
Idea远程提交spark任务到yarn集群
Study diary: February 13, 2022
The relationship between FPGA internal hardware structure and code