当前位置:网站首页>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 .
边栏推荐
- Upgrade openssl-1.1.1p for openssl-1.0.2k
- 关于slmgr命令的那些事
- Add noise randomly to open3d point cloud
- There is no network after configuring the agent by capturing packets with Fiddler mobile phones
- 15 MySQL stored procedures and functions
- 跟着CTF-wiki学pwn——ret2libc1
- C file and folder operation
- Zero rhino technology joined hands with the intelligence Club: the "causal faction" forum was successfully held, and the "causal revolution" brought the next generation of trusted AI
- 2022.7.5-----leetcode. seven hundred and twenty-nine
- 云呐|公司固定资产管理系统有哪些?
猜你喜欢

"14th five year plan": emphasis on the promotion of electronic contracts, electronic signatures and other applications

MySql——CRUD

OS i/o devices and device controllers

wx.getLocation(Object object)申请方法,最新版
![[online chat] the original wechat applet can also reply to Facebook homepage messages!](/img/d2/1fd4de4bfd433ed397c236ddb97a66.png)
[online chat] the original wechat applet can also reply to Facebook homepage messages!

Effet Doppler (déplacement de fréquence Doppler)

Miaochai Weekly - 8

软件测试工程师必会的银行存款业务,你了解多少?

Transport layer protocol ----- UDP protocol

Problems encountered in the database
随机推荐
Qt 一个简单的word文档编辑器
7.5 装饰器
【在线聊天】原来微信小程序也能回复Facebook主页消息!
CloudCompare&PCL 点云随机添加噪声
N1 # if you work on a metauniverse product [metauniverse · interdisciplinary] Season 2 S2
Miaochai Weekly - 8
The global and Chinese markets of dial indicator calipers 2022-2028: Research Report on technology, participants, trends, market size and share
【luogu CF487E】Tourists(圆方树)(树链剖分)(线段树)
MySQL global lock and table lock
QT QPushButton details
My colleagues quietly told me that flying Book notification can still play like this
Key structure of ffmpeg - avformatcontext
妙才周刊 - 8
How much do you know about the bank deposit business that software test engineers must know?
Priority queue (heap)
FFMPEG关键结构体——AVCodecContext
微信小程序---WXML 模板语法(附带笔记文档)
Cloudcompare & PCL point cloud randomly adds noise
MySql——CRUD
Zhongjun group launched electronic contracts to accelerate the digital development of real estate enterprises