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

边栏推荐
- Wonderful review of the digital Expo | highlight scientific research strength, and Zhongchuang computing power won the digital influence enterprise award
- Postman核心功能解析-参数化和测试报告
- I closed the open source project alinesno cloud service
- 链表之双指针(快慢指针,先后指针,首尾指针)
- 【Note17】PECI(Platform Environment Control Interface)
- Nanjing: full use of electronic contracts for commercial housing sales
- Tensor attribute statistics
- 关于MySQL的30条优化技巧,超实用
- Function default parameters, function placeholder parameters, function overloading and precautions
- 一文搞定垃圾回收器
猜你喜欢

Metaverse ape received $3.5 million in seed round financing from negentropy capital

航海日答题小程序之航海知识竞赛初赛

Three "factions" in the metauniverse

2022 Software Test Engineer salary increase strategy, how to reach 30K in three years

MCU case -int0 and INT1 interrupt count

实战:fabric 用户证书吊销操作流程

30 optimization skills about mysql, super practical

第一讲:蛇形矩阵

Damn, window in ie open()

Editor extensions in unity
随机推荐
Lesson 1: serpentine matrix
Ultrasonic sensor flash | LEGO eV3 Teaching
Paddle Serving v0.9.0 重磅发布多机多卡分布式推理框架
我把开源项目alinesno-cloud-service关闭了
C language - structural basis
Metaverse Ape上线倒计时,推荐活动火爆进行
Depth first DFS and breadth first BFS -- traversing adjacency tables
解决thinkphp启动时“No input file specified”的问题
FBO and RBO disappeared in webgpu
Nacos 的安装与服务的注册
New 3D particle function in QT 6.3
How to reverse a string fromCharCode? - How to reverse String. fromCharCode?
Metaverse Ape猿界应邀出席2022·粤港澳大湾区元宇宙和web3.0主题峰会,分享猿界在Web3时代从技术到应用的文明进化历程
一文搞定垃圾回收器
Methods modified by static
终于搞懂什么是动态规划的
VOT Toolkit环境配置与使用
The countdown to the launch of metaverse ape is hot
Kubernetes Administrator certification (CKA) exam notes (IV)
Damn, window in ie open()