当前位置:网站首页>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;
}
};
边栏推荐
- If you open an account of Huatai Securities by stock speculation, is it safe to open an account online?
- (脚本)一键部署redis任意版本 —— 筑梦之路
- How to do the project of computer remote company in foreign Internet?
- 【路径规划】RRT增加动力模型进行轨迹规划
- Detailed explanation of openharmony resource management
- P4281 [AHOI2008]紧急集合 / 聚会(LCA)
- TS快速入门-函数
- 实战模拟│JWT 登录认证
- Skills in analyzing the trend chart of London Silver
- [Peking University] tensorflow2.0-1-opening
猜你喜欢

如何在外地外网电脑远程公司项目?

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

Learning of basic amplification circuit

Data on the number of functional divisions of national wetland parks in Qinghai Province, data on the distribution of wetlands and marshes across the country, and natural reserves in provinces, cities

How to do the project of computer remote company in foreign Internet?

Verilog tutorial (11) initial block in Verilog

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

公司要上监控,Zabbix 和 Prometheus 怎么选?这么选准没错!

兩個數相互替換

How to avoid arc generation—— Aafd fault arc detector solves the problem for you
随机推荐
C语言中sizeof操作符的坑
JS convert pseudo array to array
uniapp上传头像
P4281 [AHOI2008]紧急集合 / 聚会(LCA)
雅思考试流程、需要具体注意些什么、怎么复习?
Acwing164. Accessibility Statistics (topological sorting +bitset)
Hash table, hash function, bloom filter, consistency hash
如何将自己的代码作品快速存证,已更好的保护自己劳动成果
AcWing164. 可达性统计(拓扑排序+bitset)
青海省国家湿地公园功能区划数数据、全国湿地沼泽分布数据、全国省市县自然保护区
两个数相互替换
Actual combat simulation │ JWT login authentication
Cross domain request
如何有效对直流列头柜进行监测
Is the account opening link of Huatai Securities with low commission safe?
Jar batch management gadget
Summer challenge brings you to play harmoniyos multi terminal piano performance
Illustrated network: what is gateway load balancing protocol GLBP?
Netcore3.1 JSON web token Middleware
Advanced template