当前位置:网站首页>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;
}
};
边栏推荐
- 兩個數相互替換
- 基本放大电路的学习
- The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
- The pit of sizeof operator in C language
- abc 258 G - Triangle(bitset)
- JS how to realize array to tree
- 【路径规划】RRT增加动力模型进行轨迹规划
- He worked as a foreign lead and paid off all the housing loans in a year
- Hologres Query管理及超时处理
- Paper notes multi UAV collaborative monolithic slam
猜你喜欢
uniapp微信小程序拿来即用的瀑布流布局demo2(方法二)(复制粘贴即可使用,无需做其他处理)
Face recognition 5- insight face padding code practice notes
Build your own minecraft server with fast parsing
端口映射和端口转发区别是什么
js如何实现数组转树
The waterfall flow layout demo2 (method 2) used by the uniapp wechat applet (copy and paste can be used without other processing)
Fs8b711s14 electric wine bottle opener MCU IC scheme development special integrated IC
【selenium自动化】常用注解
Summer challenge brings you to play harmoniyos multi terminal piano performance
Pytoch --- use pytoch to realize linknet for semantic segmentation
随机推荐
图解网络:什么是网关负载均衡协议GLBP?
青海省国家湿地公园功能区划数数据、全国湿地沼泽分布数据、全国省市县自然保护区
[IELTS reading] Wang Xiwei reads P4 (matching2 paragraph information matching question [difficult])
Business implementation - the log is written to the same row of data
[error reporting] "typeerror: cannot read properties of undefined (reading 'split')“
IT转测试岗,从迷茫到坚定我究竟付出了什么?
Verilog tutorial (11) initial block in Verilog
(脚本)一键部署redis任意版本 —— 筑梦之路
两个数相互替换
Enterprise application business scenarios, function addition and modification of C source code
Réseau graphique: Qu'est - ce que le Protocole d'équilibrage de charge de passerelle glbp?
How to do the project of computer remote company in foreign Internet?
Two numbers replace each other
[IELTS reading] Wang Xiwei reading P3 (heading)
企业应用业务场景,功能添加和修改C#源码
Netcore3.1 JSON web token Middleware
Go pit - no required module provides Package: go. Mod file not found in current directory or any parent
Upload avatar on uniapp
How to use fast parsing to make IOT cloud platform
js如何实现数组转树