当前位置:网站首页>LeetCode 1189. Maximum number of "balloons"
LeetCode 1189. Maximum number of "balloons"
2022-07-06 00:09:00 【Daylight629】
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^4textAll consist of lowercase English letters
Two 、 Method 1
simulation
class Solution {
public int maxNumberOfBalloons(String text) {
int[] cnt = new int[5];
for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
if (c == 'b') {
cnt[0]++;
} else if (c == 'a') {
cnt[1]++;
} else if (c == 'l') {
cnt[2]++;
} else if (c == 'o') {
cnt[3]++;
} else if (c == 'n') {
cnt[4]++;
}
}
cnt[2] /= 2;
cnt[3] /= 2;
return Arrays.stream(cnt).min().getAsInt();
}
}
Complexity analysis
Time complexity :O(n + C), among nn Is the length of the string ,C Indicates the number of types of characters in a word , In the subject C = 5. You need to traverse the string , And find the minimum number of characters in the word .
Spatial complexity :O(C ),C Indicates the number of types of characters in a word , In the subject C=5. need O(C ) The statistical number of characters stored in the space of .
边栏推荐
- 用列表初始化你的vector&&initializer_list简介
- Permission problem: source bash_ profile permission denied
- The use of El cascader and the solution of error reporting
- 硬件及接口学习总结
- CloudCompare&PCL 点云随机添加噪声
- MySQL functions
- openssl-1.0.2k版本升级openssl-1.1.1p
- Global and Chinese market of digital serial inverter 2022-2028: Research Report on technology, participants, trends, market size and share
- [SQL] SQL expansion languages of mainstream databases (T-SQL, pl/sql, pl/pgsql)
- 微信小程序---WXML 模板语法(附带笔记文档)
猜你喜欢

Huawei equipment is configured with OSPF and BFD linkage

Detailed explanation of APP functions of door-to-door appointment service

18. (ArcGIS API for JS) ArcGIS API for JS point collection (sketchviewmodel)

XML configuration file (DTD detailed explanation)

Mysql - CRUD

Wechat applet -- wxml template syntax (with notes)

妙才周刊 - 8

Determinant learning notes (I)

Permission problem: source bash_ profile permission denied

Knowledge about the memory size occupied by the structure
随机推荐
7.5 simulation summary
【luogu P3295】萌萌哒(并查集)(倍增)
Open3D 点云随机添加噪声
7.5 decorator
Initialize your vector & initializer with a list_ List introduction
Transport layer protocol ----- UDP protocol
Hudi of data Lake (1): introduction to Hudi
Global and Chinese markets for hinged watertight doors 2022-2028: Research Report on technology, participants, trends, market size and share
软件测试工程师必会的银行存款业务,你了解多少?
How to rotate the synchronized / refreshed icon (EL icon refresh)
The use of El cascader and the solution of error reporting
[SQL] SQL expansion languages of mainstream databases (T-SQL, pl/sql, pl/pgsql)
NSSA area where OSPF is configured for Huawei equipment
Configuring OSPF load sharing for Huawei devices
"14th five year plan": emphasis on the promotion of electronic contracts, electronic signatures and other applications
Global and Chinese market of digital serial inverter 2022-2028: Research Report on technology, participants, trends, market size and share
Determinant learning notes (I)
云呐|公司固定资产管理系统有哪些?
认识提取与显示梅尔谱图的小实验(观察不同y_axis和x_axis的区别)
DEJA_ Vu3d - cesium feature set 055 - summary description of map service addresses of domestic and foreign manufacturers