当前位置:网站首页>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 .
边栏推荐
- JS 这次真的可以禁止常量修改了!
- MySql——CRUD
- Senparc. Weixin. Sample. MP source code analysis
- 剖面测量之提取剖面数据
- 数据库遇到的问题
- 【QT】Qt使用QJson生成json文件并保存
- 20220703 week race: number of people who know the secret - dynamic rules (problem solution)
- Redis high availability - master-slave replication, sentinel mode, cluster
- After summarizing more than 800 kubectl aliases, I'm no longer afraid that I can't remember commands!
- QT -- thread
猜你喜欢
What if the C disk is not enough? Let's see how I can clean up 25g of temp disk space after I haven't redone the system for 4 years?
Zhongjun group launched electronic contracts to accelerate the digital development of real estate enterprises
[online chat] the original wechat applet can also reply to Facebook homepage messages!
Choose to pay tribute to the spirit behind continuous struggle -- Dialogue will values [Issue 4]
单商户V4.4,初心未变,实力依旧!
20220703 week race: number of people who know the secret - dynamic rules (problem solution)
【在线聊天】原来微信小程序也能回复Facebook主页消息!
剖面测量之提取剖面数据
Problem solving win10 quickly open ipynb file
MySql——CRUD
随机推荐
Senparc. Weixin. Sample. MP source code analysis
Teach you to run uni app with simulator on hbuilderx, conscience teaching!!!
Problems encountered in the database
The difference of time zone and the time library of go language
QT a simple word document editor
How to get all the values stored in localstorage
亲测可用fiddler手机抓包配置代理后没有网络
C # input how many cards are there in each of the four colors.
MySQL functions
wx. Getlocation (object object) application method, latest version
微信小程序---WXML 模板语法(附带笔记文档)
【luogu P3295】萌萌哒(并查集)(倍增)
上门预约服务类的App功能详解
wx.getLocation(Object object)申请方法,最新版
教你在HbuilderX上使用模拟器运行uni-app,良心教学!!!
Make a short video clip number of we media film and television. Where can I download the material?
Global and Chinese markets of POM plastic gears 2022-2028: Research Report on technology, participants, trends, market size and share
单商户V4.4,初心未变,实力依旧!
FFMPEG关键结构体——AVFormatContext
[EF core] mapping relationship between EF core and C data type