当前位置:网站首页>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
边栏推荐
- Metasploit(msf)利用ms17_010(永恒之蓝)出现Encoding::UndefinedConversionError问题
- 从 1.5 开始搭建一个微服务框架——日志追踪 traceId
- a-tree 树的全部展开和收起
- Metaverse Ape猿界应邀出席2022·粤港澳大湾区元宇宙和web3.0主题峰会,分享猿界在Web3时代从技术到应用的文明进化历程
- Three "factions" in the metauniverse
- 【无标题】
- Shelved in TortoiseSVN- Shelve in TortoiseSVN?
- Why does the C# compiler allow an explicit cast between IEnumerable&lt; T&gt; and TAlmostAnything?
- 记录几个常见问题(202207)
- Evolution of APK reinforcement technology, APK reinforcement technology and shortcomings
猜你喜欢
从 1.5 开始搭建一个微服务框架——日志追踪 traceId
Postman core function analysis - parameterization and test report
Common model making instructions
700. Search in a Binary Search Tree. Sol
BFC block level formatting context
My experience and summary of the new Zhongtai model
一文搞定class的微观结构和指令
Distance from point to line intersection and included angle of line
Distance entre les points et les lignes
Wonderful review of the digital Expo | highlight scientific research strength, and Zhongchuang computing power won the digital influence enterprise award
随机推荐
Roman numeral to integer
The code generator has deoptimised the styling of xx/typescript. js as it exceeds the max of 500kb
我把开源项目alinesno-cloud-service关闭了
谷歌地图案例
Nangou Gili hard Kai font TTF Download with installation tutorial
Paddy serving v0.9.0 heavy release multi machine multi card distributed reasoning framework
Depth first DFS and breadth first BFS -- traversing adjacency tables
一文搞定JVM常见工具和优化策略
请求二进制数据和base64格式数据的预览显示
链表之双指针(快慢指针,先后指针,首尾指针)
a-tree 树的全部展开和收起
GWT module may need to be (RE) compiled reduce - GWT module may need to be (RE) compiled reduce
Function default parameters, function placeholder parameters, function overloading and precautions
Starting from 1.5, build a micro Service Framework -- log tracking traceid
Metasploit (MSF) uses MS17_ 010 (eternal blue) encoding:: undefined conversionerror problem
Navigation day answer applet: preliminary competition of navigation knowledge competition
點到直線的距離直線的交點及夾角
IIC bus realizes client device
Metaverse ape received $3.5 million in seed round financing from negentropy capital
50. Pow(x, n). O(logN) Sol