当前位置:网站首页>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;
}
边栏推荐
- Express
- CSAPP shell lab experiment report
- HackTheBox-Emdee five for life
- 遇到程序员不修改bug时怎么办?我教你
- 接口测试面试题及参考答案,轻松拿捏面试官
- Software testing interview summary - common interview questions
- Investment operation steps
- Build your own application based on Google's open source tensorflow object detection API video object recognition system (II)
- The minimum number of operations to convert strings in leetcode simple problem
- Interface test interview questions and reference answers, easy to grasp the interviewer
猜你喜欢
UCORE lab7 synchronous mutual exclusion experiment report
Eigen User Guide (Introduction)
Video scrolling subtitle addition, easy to make with this technique
Example 071 simulates a vending machine, designs a program of the vending machine, runs the program, prompts the user, enters the options to be selected, and prompts the selected content after the use
Sleep quality today 81 points
CSAPP家庭作业答案7 8 9章
Do you know the advantages and disadvantages of several open source automated testing frameworks?
软件测试需求分析之什么是“试纸测试”
线程及线程池
CSAPP shell lab experiment report
随机推荐
What if software testing is too busy to study?
What are the software testing methods? Show you something different
自动化测试你必须要弄懂的问题,精品总结
Practical cases, hand-in-hand teaching you to build e-commerce user portraits | with code
Want to learn how to get started and learn software testing? I'll give you a good chat today
Knowledge that you need to know when changing to software testing
How to change XML attribute - how to change XML attribute
ucore lab6 调度器 实验报告
Cadence physical library lef file syntax learning [continuous update]
C4D quick start tutorial - creating models
Threads and thread pools
ucore lab8 文件系统 实验报告
線程及線程池
Sleep quality today 81 points
How to learn automated testing in 2022? This article tells you
Investment should be calm
Global and Chinese market of DVD recorders 2022-2028: Research Report on technology, participants, trends, market size and share
MySQL数据库(四)事务和函数
ByteDance ten years of experience, old bird, took more than half a year to sort out the software test interview questions
Programmers, how to avoid invalid meetings?