当前位置:网站首页>Winter vacation daily question - maximum number of balloons
Winter vacation daily question - maximum number of balloons
2022-07-06 15:17:00 【A cat that doesn't eat mice】
- Topic link :https://leetcode-cn.com/problems/maximum-number-of-balloons/
- Title Description
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
Input :text = "loonbalxballpoon"
Output :2
Ideas
Statistical letters b,a,l,o,n Number of occurrences of , Choose the one with the least number of occurrences ( Be careful :o , l When comparing, divide by 2)
- Code
public int maxNumberOfBalloons(String text) {
// Count the number of each word
int[] nums = new int[26];
char[] chars = text.toCharArray();
for (char c : chars) {
int i = c - 'a';
nums[i]++;
}
int min = nums[0];
for (int i = 0; i < nums.length; i++) {
if (i+'a'=='b' || i+'a'=='n')
min = Math.min(min,nums[i]);
if (i+'a'=='l' || i+'a'=='o')
min = Math.min(min,nums[i]/2);
}
return min;
}
边栏推荐
- 基于485总线的评分系统双机实验报告
- What are the business processes and differences of the three basic business modes of Vos: direct dial, callback and semi direct dial?
- ucore lab1 系统软件启动过程 实验报告
- Knowledge that you need to know when changing to software testing
- MySQL数据库(二)DML数据操作语句和基本的DQL语句
- Servlet
- Word macro operation: convert the automatic number in the document into editable text type
- 全网最详细的postman接口测试教程,一篇文章满足你
- UCORE lab8 file system experiment report
- CSAPP homework answers chapter 789
猜你喜欢
Word macro operation: convert the automatic number in the document into editable text type
C language do while loop classic Level 2 questions
Servlet
安全测试入门介绍
What is "test paper test" in software testing requirements analysis
Interface test interview questions and reference answers, easy to grasp the interviewer
Réponses aux devoirs du csapp 7 8 9
C4D quick start tutorial - Introduction to software interface
遇到程序员不修改bug时怎么办?我教你
What are the commonly used SQL statements in software testing?
随机推荐
Want to learn how to get started and learn software testing? I'll give you a good chat today
CSAPP家庭作業答案7 8 9章
Do you know the advantages and disadvantages of several open source automated testing frameworks?
CSAPP shell lab experiment report
MySQL数据库(三)高级数据查询语句
How to do agile testing in automated testing?
Cadence physical library lef file syntax learning [continuous update]
CSAPP homework answers chapter 789
Software testing interview summary - common interview questions
全网最详细的postman接口测试教程,一篇文章满足你
Sleep quality today 81 points
Leetcode notes - dynamic planning -day6
线程及线程池
ucore lab8 文件系统 实验报告
Cc36 different subsequences
ucore lab2 物理内存管理 实验报告
What if software testing is too busy to study?
Video scrolling subtitle addition, easy to make with this technique
If the position is absolute, touchablehighlight cannot be clicked - touchablehighlight not clickable if position absolute
線程及線程池