当前位置:网站首页>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
边栏推荐
- 激动人心,2022开放原子全球开源峰会报名火热开启
- MCU realizes OTA online upgrade process through UART
- 【第30天】给定一个整数 n ,求它的因数之和
- Zhuhai laboratory ventilation system construction and installation instructions
- Convert binary search tree into cumulative tree (reverse middle order traversal)
- For a deadline, the IT fellow graduated from Tsinghua suddenly died on the toilet
- 1791. Find the central node of the star diagram / 1790 Can two strings be equal by performing string exchange only once
- How spark gets columns in dataframe --column, $, column, apply
- Spark SQL UDF function
- How to use the flutter framework to develop and run small programs
猜你喜欢

The third season of ape table school is about to launch, opening a new vision for developers under the wave of going to sea
![[groovy] compile time meta programming (AST syntax tree conversion with annotations | define annotations and use groovyasttransformationclass to indicate ast conversion interface | ast conversion inte](/img/61/73becfc3b46669d31b0cf334aa54f2.jpg)
[groovy] compile time meta programming (AST syntax tree conversion with annotations | define annotations and use groovyasttransformationclass to indicate ast conversion interface | ast conversion inte

关于#数据库#的问题:(5)查询库存表中每本书的条码、位置和借阅的读者编号

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

从 1.5 开始搭建一个微服务框架——调用链追踪 traceId

MySQL storage engine

Xunrui CMS plug-in automatically collects fake original free plug-ins

Introduction of motor

Idea remotely submits spark tasks to the yarn cluster

Daily practice - February 13, 2022
随机推荐
Mobilenet series (5): use pytorch to build mobilenetv3 and learn and train based on migration
The population logic of the request to read product data on the sap Spartacus home page
C language programming (Chapter 6 functions)
Overview of Zhuhai purification laboratory construction details
测试/开发程序员的成长路线,全局思考问题的问题......
Free chat robot API
Extension and application of timestamp
Lone brave man
Pbootcms plug-in automatically collects fake original free plug-ins
[groovy] XML serialization (use markupbuilder to generate XML data | set XML tag content | set XML tag attributes)
Differences between standard library functions and operators
激动人心,2022开放原子全球开源峰会报名火热开启
[groovy] compile time metaprogramming (compile time method interception | find the method to be intercepted in the myasttransformation visit method)
Hundreds of lines of code to implement a JSON parser
Four dimensional matrix, flip (including mirror image), rotation, world coordinates and local coordinates
小程序容器可以发挥的价值
Building core knowledge points
How to make your own robot
cf:C. The Third Problem【关于排列这件事】
Introduction to robotics I. spatial transformation (1) posture, transformation