当前位置:网站首页>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
边栏推荐
- Starting from 1.5, build a micro Service Framework -- log tracking traceid
- Function default parameters, function placeholder parameters, function overloading and precautions
- Request preview display of binary data and Base64 format data
- 50. Pow(x, n). O(logN) Sol
- Assign the output of a command to a variable [repeat] - assigning the output of a command to a variable [duplicate]
- Nacos 的安装与服务的注册
- Three "factions" in the metauniverse
- 如何快速体验OneOS
- How to create a thread
- 344. Reverse String. Sol
猜你喜欢
Three "factions" in the metauniverse
90后测试员:“入职阿里,这一次,我决定不在跳槽了”
[secretly kill little buddy pytorch20 days] - [Day2] - [example of picture data modeling process]
TCC of distributed solutions
Solutions for unexplained downtime of MySQL services
How to quickly experience oneos
513. Find the value in the lower left corner of the tree
[untitled]
Practice: fabric user certificate revocation operation process
First, redis summarizes the installation types
随机推荐
How to quickly experience oneos
Navigation day answer applet: preliminary competition of navigation knowledge competition
Metasploit (MSF) uses MS17_ 010 (eternal blue) encoding:: undefined conversionerror problem
Double pointeur de liste liée (pointeur rapide et lent, pointeur séquentiel, pointeur de tête et de queue)
Some tutorials install the database on ubantu so as not to occupy computer memory?
Request preview display of binary data and Base64 format data
实战:fabric 用户证书吊销操作流程
[error record] groovy function parameter dynamic type error (guess: groovy.lang.missingmethodexception: no signature of method)
Assign the output of a command to a variable [repeat] - assigning the output of a command to a variable [duplicate]
Nacos installation and service registration
509. Fibonacci Number. Sol
[groovy] groovy dynamic language features (automatic type inference of function arguments in groovy | precautions for function dynamic parameters)
2022.02.13 - SX10-30. Home raiding II
How can easycvr cluster deployment solve the massive video access and concurrency requirements in the project?
[groovy] mop meta object protocol and meta programming (Introduction to groovyobject interface | introduction to metaclass | implementation of class methods using groovyobject invokemethod)
Platformio create libopencm3 + FreeRTOS project
thinkphp5.1跨域问题解决
C language - structural basis
GWT module may need to be (RE) compiled reduce - GWT module may need to be (RE) compiled reduce
Sparse array [matrix]