当前位置:网站首页>【leetcode】1189. Maximum number of "balloons"
【leetcode】1189. Maximum number of "balloons"
2022-07-06 03:56:00 【Chinese fir sauce_】
subject :
1189. “ balloon ” Maximum number of
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
class Solution {
public int maxNumberOfBalloons(String text) {
char[] ch = text.toCharArray();
Map<Character,Integer> map = new HashMap<>();
for(int i = 0; i < ch.length;i++){
map.put(ch[i],map.getOrDefault(ch[i],0) + 1 );
}
int res = 0;
int b = map.getOrDefault('b',0);
int a = map.getOrDefault('a',0);
int l = map.getOrDefault('l',0) / 2;
int o = map.getOrDefault('o',0) / 2;
int n = map.getOrDefault('n',0);
res = Math.min(a,b);
res = Math.min(res,l);
res = Math.min(res,o);
res = Math.min(res,n);
return res;
}
}
边栏推荐
- Cubemx transplantation punctual atom LCD display routine
- Custom event of C (31)
- 3.2 detailed explanation of rtthread serial port device (V2)
- Overview of super-resolution reconstruction of remote sensing images
- How to modify field constraints (type, default, null, etc.) in a table
- MySQL 中的数据类型介绍
- Image super resolution using deep revolutionary networks (srcnn) interpretation and Implementation
- 2. GPIO related operations
- C#(三十)之C#comboBox ListView treeView
- BUAA magpie nesting
猜你喜欢
Benefits of automated testing
SSTI template injection explanation and real problem practice
【PSO】基于PSO粒子群优化的物料点货物运输成本最低值计算matlab仿真,包括运输费用、代理人转换费用、运输方式转化费用和时间惩罚费用
BUAA喜鹊筑巢
[introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
Recommended papers on remote sensing image super-resolution
Interface idempotency
2.2 STM32 GPIO operation
MySQL about self growth
Facebook等大廠超十億用戶數據遭泄露,早該關注DID了
随机推荐
关于非虚函数的假派生
RT-Thread--Lwip之FTP(2)
[introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
2.2 STM32 GPIO operation
C#(三十一)之自定义事件
Take you to wechat applet development in 3 minutes
mysql从一个连续时间段的表中读取缺少数据
In Net 6 CS more concise method
MySql数据库root账户无法远程登陆解决办法
51nod 1130 n factorial length V2 (Stirling approximation)
C (XXIX) C listbox CheckedListBox Imagelist
C language circular statement
MySQL master-slave replication
RT thread -- FTP of LwIP (2)
Do you know cookies, sessions, tokens?
Suggestions for new engineer team members
[FPGA tutorial case 12] design and implementation of complex multiplier based on vivado core
[meisai] meisai thesis reference template
Pytoch foundation - (1) initialization of tensors
math_ Derivative function derivation of limit & differential & derivative & derivative / logarithmic function (derivative definition limit method) / derivative formula derivation of exponential functi