当前位置:网站首页>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;
}
边栏推荐
- Nest and merge new videos, and preset new video titles
- Global and Chinese market of goat milk powder 2022-2028: Research Report on technology, participants, trends, market size and share
- How to rename multiple folders and add unified new content to folder names
- How to become a good software tester? A secret that most people don't know
- Global and Chinese market of maleic acid modified rosin esters 2022-2028: Research Report on technology, participants, trends, market size and share
- Soft exam information system project manager_ Project set project portfolio management --- Senior Information System Project Manager of soft exam 025
- Future trend and planning of software testing industry
- MySQL数据库(四)事务和函数
- Face and eye recognition based on OpenCV's own model
- Heap, stack, queue
猜你喜欢

UCORE lab8 file system experiment report

What are the commonly used SQL statements in software testing?

How to become a good software tester? A secret that most people don't know

ucore lab7 同步互斥 实验报告
![[pytorch] simple use of interpolate](/img/16/87aa8a49e60801404822fe644e70c8.jpg)
[pytorch] simple use of interpolate

全网最详细的postman接口测试教程,一篇文章满足你

MySQL数据库(四)事务和函数
![Cadence physical library lef file syntax learning [continuous update]](/img/0b/75a4ac2649508857468d9b37703a27.jpg)
Cadence physical library lef file syntax learning [continuous update]

MySQL development - advanced query - take a good look at how it suits you

ucore lab8 文件系统 实验报告
随机推荐
Global and Chinese market of maleic acid modified rosin esters 2022-2028: Research Report on technology, participants, trends, market size and share
Leetcode notes - dynamic planning -day6
Investment operation steps
Build your own application based on Google's open source tensorflow object detection API video object recognition system (I)
UCORE lab7 synchronous mutual exclusion experiment report
Collection集合与Map集合
Réponses aux devoirs du csapp 7 8 9
Global and Chinese market of goat milk powder 2022-2028: Research Report on technology, participants, trends, market size and share
Interface test interview questions and reference answers, easy to grasp the interviewer
C4D quick start tutorial - Introduction to software interface
What to do when programmers don't modify bugs? I teach you
MySQL development - advanced query - take a good look at how it suits you
ArrayList集合
UCORE lab8 file system experiment report
[HCIA continuous update] advanced features of routing
If the position is absolute, touchablehighlight cannot be clicked - touchablehighlight not clickable if position absolute
Software testing interview summary - common interview questions
The minimum sum of the last four digits of the split digit of leetcode simple problem
Mysql database (III) advanced data query statement
Interview answering skills for software testing