当前位置:网站首页>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^4
text 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
- 119. Pascal‘s Triangle II. Sol
- Thinkphp5.1 cross domain problem solving
- 抖音__ac_signature
- [agc009e] eternal average - conclusion, DP
- BFC block level formatting context
- ESP32 hosted
- Oracle is sorted by creation time. If the creation time is empty, the record is placed last
- Common model making instructions
- 从 1.5 开始搭建一个微服务框架——日志追踪 traceId
猜你喜欢
Metasploit (MSF) uses MS17_ 010 (eternal blue) encoding:: undefined conversionerror problem
All expansion and collapse of a-tree
2022软件测试工程师涨薪攻略,3年如何达到30K
Nangou Gili hard Kai font TTF Download with installation tutorial
Metasploit(msf)利用ms17_010(永恒之蓝)出现Encoding::UndefinedConversionError问题
Starting from 1.5, build a micro Service Framework -- log tracking traceid
Nacos 的安装与服务的注册
Analysis of the problem that the cookie value in PHP contains a plus sign (+) and becomes a space
一文搞定class的微观结构和指令
基于STM32的ADC采样序列频谱分析
随机推荐
Activate function and its gradient
链表之双指针(快慢指针,先后指针,首尾指针)
【无标题】
我对新中台模型的一些经验思考总结
30 optimization skills about mysql, super practical
终于搞懂什么是动态规划的
50. Pow(x, n). O(logN) Sol
Metaverse ape received $3.5 million in seed round financing from negentropy capital
Oracle is sorted by creation time. If the creation time is empty, the record is placed last
Distributed resource management and task scheduling framework yarn
谷歌地图案例
傅里叶分析概述
Solve the problem of "no input file specified" when ThinkPHP starts
Metasploit (MSF) uses MS17_ 010 (eternal blue) encoding:: undefined conversionerror problem
如何创建线程
The code generator has deoptimised the styling of xx/typescript. js as it exceeds the max of 500kb
VIM tail head intercept file import
VOT toolkit environment configuration and use
I closed the open source project alinesno cloud service
Solutions for unexplained downtime of MySQL services