当前位置:网站首页>[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();
}
}
边栏推荐
- Security design verification of API interface: ticket, signature, timestamp
- MySQL实战优化高手06 生产经验:互联网公司的生产环境数据库是如何进行性能测试的?
- Solve the problem of remote connection to MySQL under Linux in Windows
- C miscellaneous two-way circular linked list
- MySQL35-主从复制
- 使用OVF Tool工具从Esxi 6.7中导出虚拟机
- If someone asks you about the consistency of database cache, send this article directly to him
- Nanny hand-in-hand teaches you to write Gobang in C language
- MySQL30-事务基础知识
- 数据库中间件_Mycat总结
猜你喜欢
解决在window中远程连接Linux下的MySQL
Pytorch RNN actual combat case_ MNIST handwriting font recognition
13 medical registration system_ [wechat login]
Security design verification of API interface: ticket, signature, timestamp
MySQL 29 other database tuning strategies
MySQL combat optimization expert 12 what does the memory data structure buffer pool look like?
Notes of Dr. Carolyn ROS é's social networking speech
MySQL实战优化高手11 从数据的增删改开始讲起,回顾一下Buffer Pool在数据库里的地位
Mysql27 index optimization and query optimization
C miscellaneous lecture continued
随机推荐
Database middleware_ MYCAT summary
MySQL learning diary (II)
软件测试工程师必备之软技能:结构化思维
MySQL27-索引优化与查询优化
text 文本数据增强方法 data argumentation
C miscellaneous lecture continued
[Julia] exit notes - Serial
Notes of Dr. Carolyn ROS é's social networking speech
使用OVF Tool工具从Esxi 6.7中导出虚拟机
What is the current situation of the game industry in the Internet world?
MySQL21-用户与权限管理
Mysql33 multi version concurrency control
Mysql27 index optimization and query optimization
第一篇博客
解决在window中远程连接Linux下的MySQL
Sed text processing
MySQL25-索引的创建与设计原则
Transactions have four characteristics?
MySQL底层的逻辑架构
MySQL32-锁