当前位置:网站首页>[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();
}
}
边栏推荐
- In fact, the implementation of current limiting is not complicated
- MySQL combat optimization expert 04 uses the execution process of update statements in the InnoDB storage engine to talk about what binlog is?
- Database middleware_ MYCAT summary
- C language string function summary
- 如何搭建接口自动化测试框架?
- Solution to the problem of cross domain inaccessibility of Chrome browser
- The appearance is popular. Two JSON visualization tools are recommended for use with swagger. It's really fragrant
- 15 medical registration system_ [appointment registration]
- MySQL25-索引的创建与设计原则
- MySQL实战优化高手10 生产经验:如何为数据库的监控系统部署可视化报表系统?
猜你喜欢
Just remember Balabala
MySQL24-索引的数据结构
高并发系统的限流方案研究,其实限流实现也不复杂
[after reading the series of must know] one of how to realize app automation without programming (preparation)
MySQL36-数据库备份与恢复
Security design verification of API interface: ticket, signature, timestamp
Notes of Dr. Carolyn ROS é's social networking speech
Implement sending post request with form data parameter
MySQL combat optimization expert 02 in order to execute SQL statements, do you know what kind of architectural design MySQL uses?
15 medical registration system_ [appointment registration]
随机推荐
数据库中间件_Mycat总结
Use of dataset of pytorch
使用OVF Tool工具从Esxi 6.7中导出虚拟机
Pytorch LSTM实现流程(可视化版本)
Solve the problem of remote connection to MySQL under Linux in Windows
Mysql24 index data structure
Typescript入门教程(B站黑马程序员)
Water and rain condition monitoring reservoir water and rain condition online monitoring
MySQL learning diary (II)
第一篇博客
Download and installation of QT Creator
MySQL实战优化高手09 生产经验:如何为生产环境中的数据库部署监控系统?
Google login prompt error code 12501
Ueeditor internationalization configuration, supporting Chinese and English switching
Adaptive Bezier curve network for real-time end-to-end text recognition
Set shell script execution error to exit automatically
In fact, the implementation of current limiting is not complicated
How to change php INI file supports PDO abstraction layer
基于Pytorch的LSTM实战160万条评论情感分类
MySQL实战优化高手10 生产经验:如何为数据库的监控系统部署可视化报表系统?