当前位置:网站首页>Leetcode daily question 1189 The maximum number of "balloons" simple simulation questions~
Leetcode daily question 1189 The maximum number of "balloons" simple simulation questions~
2022-07-05 22:48:00 【Ape Xiaofu】
Content of this article :leetcode A daily topic 1189. “ balloon ” Maximum number of Simple simulation questions ~
Article column :leetcode A daily topic 《 Punch in daily 》
Recent updates :2022 year 2 month 12 Japan leetcode A daily topic 1020. The number of enclaves ordinary DFS Board question Find out whether it is an enclave according to whether it is connected to the boundary ~
Personal profile : A Junior Program ape in two colleges , In the spirit of paying attention to the foundation , Clock in algorithm , Sharing technology as a personal experience summary blogger , Although you may be lazy sometimes , But I will stick to it , If you like blog posts very much , Suggest looking at the following line ~( Crazy hints QwQ)
give the thumbs-up Collection Leaving a message. One key, three links Care program ape , From you and me
Contents of this article
Write it at the front
Simple simulation questions qwq It won't take a word
subject
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

Example 1:
Input :text = "nlaebolko"
Output :1

Example 2:
Input :text = "loonbalxballpoon"
Output :2
Tips
1 <= text.length <= 10^4text All consist of lowercase English letters
Ideas
This question examines the knowledge points
- Simple simulation questions , But Xiao Fu writes more , But the idea must be like this qwq
- Notice how many groups there are balloon Each group of words l And o Will be consumed first Then unify
Code implementation
Sort + The sliding window
class Solution {
public int maxNumberOfBalloons(String text) {
Map<Character ,Integer> map = new HashMap<Character,Integer>();
char[] ss = text.toCharArray();
for (int i = 0 ; i< ss.length;i++){
map.put(ss[i],map.getOrDefault(ss[i],0)+1);
}
int res = 0;
int b = map.getOrDefault('b',0);
int a = map.getOrDefault('a',0);
int l = map.getOrDefault('l',0);
int o = map.getOrDefault('o',0);
int n = map.getOrDefault('n',0);
int count1 = Math.min(Math.min(b,a),n);
int count2 = Math.min(l/2,o/2);
return Math.min(count1,count2);
}
}
Running results
Simple simulation

At the end
2022-2-13 Xiao Fu clocked in today ~
A beautiful sunrise Beautiful mountains and rivers
Because of you And bright dazzling

边栏推荐
- Paddle Serving v0.9.0 重磅发布多机多卡分布式推理框架
- thinkphp5.1跨域问题解决
- VIM tail head intercept file import
- Some tutorials install the database on ubantu so as not to occupy computer memory?
- The introduction to go language is very simple: String
- Double pointer of linked list (fast and slow pointer, sequential pointer, head and tail pointer)
- 3 find the greatest common divisor and the least common multiple
- Metasploit (MSF) uses MS17_ 010 (eternal blue) encoding:: undefined conversionerror problem
- Solve the problem of "no input file specified" when ThinkPHP starts
- Metaverse Ape获Negentropy Capital种子轮融资350万美元
猜你喜欢

My experience and summary of the new Zhongtai model

I closed the open source project alinesno cloud service

Ultrasonic sensor flash | LEGO eV3 Teaching

Distance entre les points et les lignes

Spectrum analysis of ADC sampling sequence based on stm32

Metasploit (MSF) uses MS17_ 010 (eternal blue) encoding:: undefined conversionerror problem

从 1.5 开始搭建一个微服务框架——日志追踪 traceId

What changes has Web3 brought to the Internet?

90后测试员:“入职阿里,这一次,我决定不在跳槽了”

a-tree 树的全部展开和收起
随机推荐
Distributed resource management and task scheduling framework yarn
Kubernetes Administrator certification (CKA) exam notes (IV)
Vcomp110.dll download -vcomp110 What if DLL is lost
Double pointeur de liste liée (pointeur rapide et lent, pointeur séquentiel, pointeur de tête et de queue)
Usage Summary of scriptable object in unity
Distance from point to line intersection and included angle of line
Record several frequently asked questions (202207)
How to quickly experience oneos
[error record] file search strategy in groovy project (src/main/groovy/script.groovy needs to be used in the main function | groovy script directly uses the relative path of code)
我把开源项目alinesno-cloud-service关闭了
Evolution of APK reinforcement technology, APK reinforcement technology and shortcomings
119. Pascal‘s Triangle II. Sol
APK加固技术的演变,APK加固技术和不足之处
The introduction to go language is very simple: String
南京:全面启用商品房买卖电子合同
EasyCVR集群部署如何解决项目中的海量视频接入与大并发需求?
Navigation day answer applet: preliminary competition of navigation knowledge competition
audiopolicy
Boring boring
傅里叶分析概述