当前位置:网站首页>【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;
}
}
边栏推荐
- Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage
- 在 .NET 6 中使用 Startup.cs 更简洁的方法
- WPF effect Article 191 box selection listbox
- JS Vanke banner rotation chart JS special effect
- MySQL master-slave replication
- [introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
- Développement d'un module d'élimination des bavardages à clé basé sur la FPGA
- C (XXIX) C listbox CheckedListBox Imagelist
- Flask learning and project practice 8: introduction and use of cookies and sessions
- Ks003 mall system based on JSP and Servlet
猜你喜欢
Security xxE vulnerability recurrence (XXe Lab)
简易博客系统
AcWing 243. A simple integer problem 2 (tree array interval modification interval query)
多项目编程极简用例
Blue Bridge Cup - Castle formula
How to standardize the deployment of automated testing?
记一次excel XXE漏洞
Proof of Stirling formula
RT-Thread--Lwip之FTP(2)
2.1 rtthread pin device details
随机推荐
Blue Bridge Cup - day of week
C#(二十九)之C#listBox checkedlistbox imagelist
[FPGA tutorial case 12] design and implementation of complex multiplier based on vivado core
登录mysql输入密码时报错,ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO/YES
Pytoch foundation - (1) initialization of tensors
WPF effect Article 191 box selection listbox
[optimization model] Monte Carlo method of optimization calculation
【按鍵消抖】基於FPGA的按鍵消抖模塊開發
Ipv4中的A 、B、C类网络及子网掩码
Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)
WPF效果第一百九十一篇之框选ListBox
Plus d'un milliard d'utilisateurs de grandes entreprises comme Facebook ont été compromis, il est temps de se concentrer sur le did
Blue Bridge Cup - Castle formula
[prediction model] difference method model
Schnuka: 3D vision detection application industry machine vision 3D detection
UDP reliable transport protocol (quic)
Exchange bottles (graph theory + thinking)
asp. Core is compatible with both JWT authentication and cookies authentication
多项目编程极简用例
MySql数据库root账户无法远程登陆解决办法