当前位置:网站首页>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;
}
};
边栏推荐
- P4408 [noi2003] truant children (tree diameter)
- 2022.07.03(LC_6111_统计放置房子的方式数)
- 如果炒股开华泰证券的户,在网上开户安全吗?
- What did I pay for it transfer to testing post from confusion to firmness?
- Skills in analyzing the trend chart of London Silver
- 人脸识别5- insight-face-paddle-代码实战笔记
- 快解析内网穿透帮助企业快速实现协同办公
- [论文阅读] CarveMix: A Simple Data Augmentation Method for Brain Lesion Segmentation
- Parsing of XML
- 【雅思阅读】王希伟阅读P4(matching1)
猜你喜欢
Continuous modification of business scenario functions
Learning of basic amplification circuit
How to effectively monitor the DC column head cabinet
How to do the project of computer remote company in foreign Internet?
Hash table, hash function, bloom filter, consistency hash
Design of emergency lighting evacuation indication system for urban rail transit station
公司要上监控,Zabbix 和 Prometheus 怎么选?这么选准没错!
Skills in analyzing the trend chart of London Silver
A new method for analyzing the trend chart of London Silver
JS how to realize array to tree
随机推荐
实战模拟│JWT 登录认证
How to effectively monitor the DC column head cabinet
JS how to realize array to tree
Acwing164. Accessibility Statistics (topological sorting +bitset)
abc 258 G - Triangle(bitset)
Go pit - no required module provides Package: go. Mod file not found in current directory or any parent
圖解網絡:什麼是網關負載均衡協議GLBP?
Parsing of XML
PermissionError: [Errno 13] Permission denied: ‘data. csv‘
22-07-02周总结
业务场景功能的继续修改
Two numbers replace each other
电力运维云平台:开启电力系统“无人值班、少人值守”新模式
[error reporting] "typeerror: cannot read properties of undefined (reading 'split')“
Ap8022 switching power supply small household appliances ACDC chip offline switching power supply IC
Power operation and maintenance cloud platform: open the new mode of "unattended and few people on duty" of power system
Meet ThreadPoolExecutor
Introduction to ACM combination counting
(脚本)一键部署redis任意版本 —— 筑梦之路
Fast analysis -- easy to use intranet security software