当前位置:网站首页>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

边栏推荐
猜你喜欢

南京:全面启用商品房买卖电子合同

Metaverse ape ape community was invited to attend the 2022 Guangdong Hong Kong Macao Great Bay metauniverse and Web3.0 theme summit to share the evolution of ape community civilization from technology

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

Damn, window in ie open()

鏈錶之雙指針(快慢指針,先後指針,首尾指針)

Metaverse Ape获Negentropy Capital种子轮融资350万美元

如何快速体验OneOS
![[untitled]](/img/98/aa874a72f33edf416f38cb6e92f654.png)
[untitled]

一文搞定JVM常见工具和优化策略

ESP32 hosted
随机推荐
Nacos installation and service registration
Why does the C# compiler allow an explicit cast between IEnumerable&lt; T&gt; and TAlmostAnything?
Global and Chinese market of diesel fire pump 2022-2028: Research Report on technology, participants, trends, market size and share
3 find the greatest common divisor and the least common multiple
a-tree 树的全部展开和收起
How to quickly experience oneos
Practice: fabric user certificate revocation operation process
终于搞懂什么是动态规划的
[groovy] groovy dynamic language features (automatic type inference of function arguments in groovy | precautions for function dynamic parameters)
【无标题】
Distance entre les points et les lignes
Metasploit(msf)利用ms17_010(永恒之蓝)出现Encoding::UndefinedConversionError问题
傅里叶分析概述
Binary tree (II) -- code implementation of heap
QT creator 7 beta release
IIC bus realizes client device
[error record] groovy function parameter dynamic type error (guess: groovy.lang.missingmethodexception: no signature of method)
从 1.5 开始搭建一个微服务框架——日志追踪 traceId
关于MySQL的30条优化技巧,超实用
[secretly kill little buddy pytorch20 days] - [Day2] - [example of picture data modeling process]