当前位置:网站首页>【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;
}
}
边栏推荐
- Record the pit of NETCORE's memory surge
- Multi project programming minimalist use case
- C language circular statement
- asp. Core is compatible with both JWT authentication and cookies authentication
- 3.2 detailed explanation of rtthread serial port device (V2)
- 潘多拉 IOT 开发板学习(HAL 库)—— 实验9 PWM输出实验(学习笔记)
- 使用JS完成一个LRU缓存
- SSTI template injection explanation and real problem practice
- Proof of Stirling formula
- Hashcode and equals
猜你喜欢

mysql关于自增长增长问题

MySql数据库root账户无法远程登陆解决办法

Recommended papers on remote sensing image super-resolution

Pytoch foundation - (1) initialization of tensors

在字节做测试5年,7月无情被辞,想给划水的兄弟提个醒

Record the pit of NETCORE's memory surge

Facebook等大廠超十億用戶數據遭泄露,早該關注DID了

2.1 rtthread pin device details

Thread sleep, thread sleep application scenarios

【按鍵消抖】基於FPGA的按鍵消抖模塊開發
随机推荐
Image super resolution using deep revolutionary networks (srcnn) interpretation and Implementation
mysql关于自增长增长问题
[American competition] mathematical terms
[001] [stm32] how to download STM32 original factory data
Align items and align content in flex layout
Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)
Determine which week of the month the day is
判断当天是当月的第几周
RT-Thread--Lwip之FTP(2)
Conditionally [jsonignore]
【PSO】基于PSO粒子群优化的物料点货物运输成本最低值计算matlab仿真,包括运输费用、代理人转换费用、运输方式转化费用和时间惩罚费用
简述C语言中的符号和链接库
Serial port-rs232-rs485-ttl
[meisai] meisai thesis reference template
Facebook等大厂超十亿用户数据遭泄露,早该关注DID了
使用JS完成一个LRU缓存
阿里测试师用UI自动化测试实现元素定位
Cf603e pastoral oddities [CDQ divide and conquer, revocable and search set]
Quick sort function in C language -- qsort
Scalpel like analysis of JVM -- this article takes you to peek into the secrets of JVM