当前位置:网站首页>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 .
边栏推荐
- 多普勒效應(多普勒頻移)
- PV静态创建和动态创建
- Wechat applet -- wxml template syntax (with notes)
- Laser slam learning record
- There is no network after configuring the agent by capturing packets with Fiddler mobile phones
- shardingsphere源码解析
- Global and Chinese markets for hinged watertight doors 2022-2028: Research Report on technology, participants, trends, market size and share
- DEJA_VU3D - Cesium功能集 之 055-国内外各厂商地图服务地址汇总说明
- Open source CRM customer relationship system management system source code, free sharing
- 硬件及接口学习总结
猜你喜欢
![N1 # if you work on a metauniverse product [metauniverse · interdisciplinary] Season 2 S2](/img/f3/8e237296f5948dd0488441aa625182.jpg)
N1 # if you work on a metauniverse product [metauniverse · interdisciplinary] Season 2 S2

Yunna | what are the main operating processes of the fixed assets management system

The use of El cascader and the solution of error reporting

wx.getLocation(Object object)申请方法,最新版

Initialiser votre vecteur & initialisateur avec une liste Introduction à la Liste

Knowledge about the memory size occupied by the structure

Key structure of ffmpeg - avformatcontext

【在线聊天】原来微信小程序也能回复Facebook主页消息!

The difference of time zone and the time library of go language

Mathematical model Lotka Volterra
随机推荐
GD32F4xx uIP协议栈移植记录
选择致敬持续奋斗背后的精神——对话威尔价值观【第四期】
【二叉搜索树】增删改查功能代码实现
20220703 week race: number of people who know the secret - dynamic rules (problem solution)
Global and Chinese market of water heater expansion tank 2022-2028: Research Report on technology, participants, trends, market size and share
18.(arcgis api for js篇)arcgis api for js点采集(SketchViewModel)
FFMPEG关键结构体——AVFrame
QT a simple word document editor
MySql——CRUD
Global and Chinese market of digital serial inverter 2022-2028: Research Report on technology, participants, trends, market size and share
7.5模拟赛总结
如何解决ecology9.0执行导入流程流程产生的问题
Redis high availability - master-slave replication, sentinel mode, cluster
Configuring OSPF load sharing for Huawei devices
【luogu CF487E】Tourists(圆方树)(树链剖分)(线段树)
QT -- thread
N1 # if you work on a metauniverse product [metauniverse · interdisciplinary] Season 2 S2
Chapter 16 oauth2authorizationrequestredirectwebfilter source code analysis
JS can really prohibit constant modification this time!
Effet Doppler (déplacement de fréquence Doppler)