当前位置:网站首页>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^4
text
All 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 :
边栏推荐
- After sharing the clone remote project, NPM install reports an error - CB () never called! This is an error with npm itself.
- 从autojs到冰狐智能辅助的心里历程
- LeetCode Algorithm 2181. 合并零之间的节点
- 一文读懂简单查询代价估算
- BIO模型实现多人聊天
- Machine learning plant leaf recognition
- AI on the cloud makes earth science research easier
- Proteus -- Serial Communication parity flag mode
- Fedora/rehl installation semanage
- BUU的MISC(不定时更新)
猜你喜欢
机器人类专业不同层次院校课程差异性简述-ROS1/ROS2-
Is it difficult for girls to learn software testing? The threshold for entry is low, and learning is relatively simple
Visitor tweets about how you can layout the metauniverse
Reflex WMS medium level series 3: display shipped replaceable groups
3. Business and load balancing of high architecture
Supporting title of the book from 0 to 1: ctfer's growth road (Zhou Geng)
《从0到1:CTFer成长之路》书籍配套题目(周更)
接口自动化测试框架:Pytest+Allure+Excel
医疗软件检测机构怎么找,一航软件测评是专家
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
随机推荐
Simple use of MySQL database: add, delete, modify and query
指尖上的 NFT|在 G2 上评价 Ambire,有机会获得限量版收藏品
基于购买行为数据对超市顾客进行市场细分(RFM模型)
ROS2安装及基础知识介绍
【每日一题】729. 我的日程安排表 I
[Yu Yue education] Dunhuang Literature and art reference materials of Zhejiang Normal University
Is it difficult for girls to learn software testing? The threshold for entry is low, and learning is relatively simple
Bio model realizes multi person chat
librosa音频处理教程
作者已死?AI正用艺术征服人类
万丈高楼平地起,每个API皆根基
Day 245/300 JS forEach 多层嵌套后数据无法更新到对象中
A brief introduction of reverseme in misc in the world of attack and defense
leetcode59. 螺旋矩阵 II(中等)
将ue4程序嵌入qt界面显示
[brush questions] how can we correctly meet the interview?
Fast target recognition based on pytorch and fast RCNN
MySQL high frequency interview 20 questions, necessary (important)
详解SQL中Groupings Sets 语句的功能和底层实现逻辑
Blue Bridge Cup zero Foundation National Championship - day 20