当前位置:网站首页>[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();
}
}
边栏推荐
- South China Technology stack cnn+bilstm+attention
- [Julia] exit notes - Serial
- MNIST implementation using pytoch in jupyter notebook
- MySQL Real Time Optimization Master 04 discute de ce qu'est binlog en mettant à jour le processus d'exécution des déclarations dans le moteur de stockage InnoDB.
- Just remember Balabala
- Software test engineer development planning route
- Moteur de stockage mysql23
- MySQL combat optimization expert 06 production experience: how does the production environment database of Internet companies conduct performance testing?
- PyTorch RNN 实战案例_MNIST手写字体识别
- Mysql25 index creation and design principles
猜你喜欢
随机推荐
Sed text processing
PyTorch RNN 实战案例_MNIST手写字体识别
MySQL combat optimization expert 07 production experience: how to conduct 360 degree dead angle pressure test on the database in the production environment?
Mysql27 - Optimisation des index et des requêtes
How to build an interface automation testing framework?
百度百科数据爬取及内容分类识别
Windchill配置远程Oracle数据库连接
Mysql34 other database logs
Discriminant model: a discriminant model creation framework log linear model
MySQL real battle optimization expert 11 starts with the addition, deletion and modification of data. Review the status of buffer pool in the database
text 文本数据增强方法 data argumentation
What is the current situation of the game industry in the Internet world?
MySQL25-索引的创建与设计原则
Time complexity (see which sentence is executed the most times)
[paper reading notes] - cryptographic analysis of short RSA secret exponents
Security design verification of API interface: ticket, signature, timestamp
Water and rain condition monitoring reservoir water and rain condition online monitoring
Database middleware_ MYCAT summary
MySQL Real Time Optimization Master 04 discute de ce qu'est binlog en mettant à jour le processus d'exécution des déclarations dans le moteur de stockage InnoDB.
MySQL learning diary (II)