当前位置:网站首页>[leectode 2022.2.13] maximum number of "balloons"
[leectode 2022.2.13] maximum number of "balloons"
2022-07-06 10:36:00 【Procedural ape does not lose hair 2】
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”.
Example 1:
Input :text = “nlaebolko”
Output :1
Example 2:
Input :text = “loonbalxballpoon”
Output :2
Example 3:
Input :text = “leetcode”
Output :0
Tips :
1 <= text.length <= 10^4
text All consist of lowercase English letters
java Code :
class Solution {
public int maxNumberOfBalloons(String text) {
int[] cnt = new int[5];
for (int i = 0; i < text.length(); ++i) {
char ch = text.charAt(i);
if (ch == 'b') {
cnt[0]++;
} else if (ch == 'a') {
cnt[1]++;
} else if (ch == 'l') {
cnt[2]++;
} else if (ch == 'o') {
cnt[3]++;
} else if (ch == 'n') {
cnt[4]++;
}
}
cnt[2] /= 2;
cnt[3] /= 2;
return Arrays.stream(cnt).min().getAsInt();
}
}
边栏推荐
- Super detailed steps for pushing wechat official account H5 messages
- Redis集群方案应该怎么做?都有哪些方案?
- Windchill configure remote Oracle database connection
- Download and installation of QT Creator
- Windchill配置远程Oracle数据库连接
- MNIST implementation using pytoch in jupyter notebook
- Time in TCP state_ The role of wait?
- text 文本数据增强方法 data argumentation
- Flash operation and maintenance script (running for a long time)
- MySQL24-索引的数据结构
猜你喜欢
MySQL31-MySQL事务日志
What should the redis cluster solution do? What are the plans?
[unity] simulate jelly effect (with collision) -- tutorial on using jellysprites plug-in
In fact, the implementation of current limiting is not complicated
Mysql23 storage engine
If someone asks you about the consistency of database cache, send this article directly to him
MySQL22-逻辑架构
MySQL實戰優化高手04 借著更新語句在InnoDB存儲引擎中的執行流程,聊聊binlog是什麼?
实现以form-data参数发送post请求
高并发系统的限流方案研究,其实限流实现也不复杂
随机推荐
MySQL storage engine
Pytorch LSTM实现流程(可视化版本)
Several errors encountered when installing opencv
Implement sending post request with form data parameter
Mysql34 other database logs
[unity] simulate jelly effect (with collision) -- tutorial on using jellysprites plug-in
MySQL實戰優化高手04 借著更新語句在InnoDB存儲引擎中的執行流程,聊聊binlog是什麼?
Mysql33 multi version concurrency control
Windchill配置远程Oracle数据库连接
C miscellaneous two-way circular linked list
14 medical registration system_ [Alibaba cloud OSS, user authentication and patient]
Anaconda3 安装cv2
MySQL combat optimization expert 10 production experience: how to deploy visual reporting system for database monitoring system?
Mysql36 database backup and recovery
MySQL real battle optimization expert 08 production experience: how to observe the machine performance 360 degrees without dead angle in the process of database pressure test?
MySQL combat optimization expert 07 production experience: how to conduct 360 degree dead angle pressure test on the database in the production environment?
MySQL36-数据库备份与恢复
MySQL combat optimization expert 05 production experience: how to plan the database machine configuration in the real production environment?
C miscellaneous dynamic linked list operation
评估方法的优缺点