当前位置:网站首页>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^4
text
All 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 .
边栏推荐
- Configuring OSPF GR features for Huawei devices
- 云呐|固定资产管理系统主要操作流程有哪些
- Global and Chinese market of digital serial inverter 2022-2028: Research Report on technology, participants, trends, market size and share
- FFMPEG关键结构体——AVFormatContext
- Zhongjun group launched electronic contracts to accelerate the digital development of real estate enterprises
- Detailed explanation of APP functions of door-to-door appointment service
- Make a short video clip number of we media film and television. Where can I download the material?
- [day39 literature extensive reading] a Bayesian perspective on magnetic estimation
- [EF core] mapping relationship between EF core and C data type
- FFT 学习笔记(自认为详细)
猜你喜欢
PV static creation and dynamic creation
[day39 literature extensive reading] a Bayesian perspective on magnetic estimation
[noi simulation] Anaid's tree (Mobius inversion, exponential generating function, Ehrlich sieve, virtual tree)
Senparc.Weixin.Sample.MP源码剖析
China Jinmao online electronic signature, accelerating the digitization of real estate business
[designmode] composite mode
Learn PWN from CTF wiki - ret2libc1
FFMPEG关键结构体——AVFrame
PV静态创建和动态创建
Key structure of ffmpeg - avframe
随机推荐
Qt QPushButton详解
剖面测量之提取剖面数据
C # input how many cards are there in each of the four colors.
Tips for using pads router
QT a simple word document editor
CloudCompare&PCL 点云随机添加噪声
GD32F4xx uIP协议栈移植记录
Open source CRM customer relationship system management system source code, free sharing
QT QPushButton details
Add noise randomly to open3d point cloud
Problems encountered in the database
Upgrade openssl-1.1.1p for openssl-1.0.2k
Choose to pay tribute to the spirit behind continuous struggle -- Dialogue will values [Issue 4]
USB Interface USB protocol
如何解决ecology9.0执行导入流程流程产生的问题
Senparc. Weixin. Sample. MP source code analysis
15 MySQL stored procedures and functions
Hardware and interface learning summary
[designmode] Decorator Pattern
Global and Chinese markets of POM plastic gears 2022-2028: Research Report on technology, participants, trends, market size and share