当前位置:网站首页>1189. Maximum number of "balloons"
1189. Maximum number of "balloons"
2022-07-06 06:57:00 【_ Alkaid_】
difficulty : Simple
Catalog
2、 Time complexity and Spatial complexity
One 、 Problem description
I'm going to use LeetCode The description above .
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".
Here is an example :

Tips :
1 <= text.length <= 10^4textAll consist of lowercase English letters
Two 、 Ideas
Need to use the given text Put together as many pieces as possible "balloon" that , We need statistics text in Existing characters :' b ', ' a ', ' l ', ' o ', ' n ' The number of . And then calculate , The current character ' b ', ' a ', ' l ', ' o ', ' n ' How many can be formed by the number of "balloon" . Because here "balloon" in ' l ' And ' o ' The number of Are the two , The number of other characters is one , So the statistics are finished After the number of characters . The character ' l ' And ' o ' The number of Divide by two , Retake ' b ', ' a ', ' l ', ' o ', ' n ' The number of minimum value , That is, it can form "balloon" The number of .
3、 ... and 、 Problem solving
1、 Code implementation
class Solution {
public:
int maxNumberOfBalloons(string text) {
unordered_map<char,int> hashTable;
for(auto& item : text){
if(item == 'b' or
item == 'a' or
item == 'l' or
item == 'o' or
item == 'n'){
hashTable[item]++;
}
}
hashTable['l'] /= 2;
hashTable['o'] /= 2;
int ans = min(hashTable['b'],min(hashTable['a'],min(hashTable['l'],min(hashTable['o'],hashTable['n']))));
return ans;
}
};
2、 Time complexity and Spatial complexity
Time complexity :
,n by text Size .
Spatial complexity :
边栏推荐
猜你喜欢

Map of mL: Based on the adult census income two classification prediction data set (whether the predicted annual income exceeds 50K), use the map value to realize the interpretable case of xgboost mod

雲上有AI,讓地球科學研究更省力

Office doc add in - Online CS

Every API has its foundation when a building rises from the ground
![[English] Verb Classification of grammatical reconstruction -- English rabbit learning notes (2)](/img/3c/c25e7cbef9be1860842e8981f72352.png)
[English] Verb Classification of grammatical reconstruction -- English rabbit learning notes (2)

Fedora/rehl installation semanage

Introduction to ros2 installation and basic knowledge

Basic commands of MySQL

机器学习植物叶片识别

Pallet management in SAP SD delivery process
随机推荐
Every API has its foundation when a building rises from the ground
开源的网易云音乐API项目都是怎么实现的?
因高额网络费用,Arbitrum 奥德赛活动暂停,Nitro 发行迫在眉睫
Day 248/300 thoughts on how graduates find jobs
云上有AI,让地球科学研究更省力
Setting and using richview trvstyle template style
My creation anniversary
[Yu Yue education] Dunhuang Literature and art reference materials of Zhejiang Normal University
Pymongo gets a list of data
RichView TRVStyle 模板样式的设置与使用
软件测试外包到底要不要去?三年真实外包感受告诉你
A method to measure the similarity of time series: from Euclidean distance to DTW and its variants
Automated test environment configuration
A brief introduction of reverseme in misc in the world of attack and defense
Fast target recognition based on pytorch and fast RCNN
【Hot100】739. 每日温度
Pallet management in SAP SD delivery process
SSO process analysis
Reflex WMS中阶系列3:显示已发货可换组
指尖上的 NFT|在 G2 上评价 Ambire,有机会获得限量版收藏品