当前位置:网站首页>1189. Maximum number of "balloons"
1189. Maximum number of "balloons"
2022-07-05 00:20:00 【Phoenix_ ZengHao】
subject
1189.“ balloon ” Maximum number of
The main idea of the topic
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”.
Examples

Data scale

Ideas
Considering the composition of words b a l l o o n balloon balloon, There is no need to care about their order . And it is clear that each letter can only be used once , So count the number of each letter directly , Then the number of words that can be formed at last is m i n ( b , a , l / 2 , o / 2 , n ) min(b,a,l/2,o/2,n) min(b,a,l/2,o/2,n).
Code
class Solution {
public:
int vis[30];
int maxNumberOfBalloons(string text) {
for(int i=0;i<text.length();i++){
vis[text[i]-'a']++;
}
int ans=min(vis[1],min(vis[0],min(vis['l'-'a']/2,min(vis['o'-'a']/2,vis['n'-'a']))));
return ans;
}
};
边栏推荐
- JS convert pseudo array to array
- (脚本)一键部署redis任意版本 —— 筑梦之路
- [论文阅读] CarveMix: A Simple Data Augmentation Method for Brain Lesion Segmentation
- Basic points of the game setup of the points mall
- 【报错】 “TypeError: Cannot read properties of undefined (reading ‘split‘)“
- How to reduce the stock account Commission and stock speculation commission? Is it safe to open an online account
- [IELTS reading] Wang Xiwei reading P4 (matching1)
- [path planning] RRT adds dynamic model for trajectory planning
- Parsing of XML
- 海思3559万能平台搭建:YUV422的踩坑记录
猜你喜欢

城市轨道交通站应急照明疏散指示系统设计

Deux nombres se remplacent

圖解網絡:什麼是網關負載均衡協議GLBP?

Mit-6.824-lab4b-2022 (10000 word idea explanation - code construction)

青海省国家湿地公园功能区划数数据、全国湿地沼泽分布数据、全国省市县自然保护区
![[path planning] RRT adds dynamic model for trajectory planning](/img/98/dd9b106fd9dc64e676d9c943c03ab3.jpg)
[path planning] RRT adds dynamic model for trajectory planning

Ap8022 switching power supply small household appliances ACDC chip offline switching power supply IC

Fs8b711s14 electric wine bottle opener MCU IC scheme development special integrated IC

端口映射和端口转发区别是什么

Tester's algorithm interview question - find mode
随机推荐
Paper notes multi UAV collaborative monolithic slam
Deux nombres se remplacent
快解析内网穿透帮助企业快速实现协同办公
P3304 [SDOI2013]直径(树的直径)
JS 将伪数组转换成数组
Every time I look at the interface documents of my colleagues, I get confused and have a lot of problems...
uniapp上传头像
圖解網絡:什麼是網關負載均衡協議GLBP?
XML的解析
巩固表达式C# 案例简单变量运算
How to do the project of computer remote company in foreign Internet?
[论文阅读] TUN-Det: A Novel Network for Thyroid Ultrasound Nodule Detection
(script) one click deployment of any version of redis - the way to build a dream
【雅思阅读】王希伟阅读P3(Heading)
[IELTS reading] Wang Xiwei reads P4 (matching2 paragraph information matching question [difficult])
How to reduce the stock account Commission and stock speculation commission? Is it safe to open an online account
业务实现-日志写到同一个行数据里面
【C】(笔试题)指针与数组,指针
PermissionError: [Errno 13] Permission denied: ‘data. csv‘
Application of multi loop instrument in base station "switching to direct"