当前位置:网站首页>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;
}
边栏推荐
- [HCIA continuous update] advanced features of routing
- Express
- DVWA exercise 05 file upload file upload
- ArrayList集合
- Expanded polystyrene (EPS) global and Chinese markets 2022-2028: technology, participants, trends, market size and share Research Report
- STC-B学习板蜂鸣器播放音乐2.0
- What to do when programmers don't modify bugs? I teach you
- 软件测试工作太忙没时间学习怎么办?
- Install and run tensorflow object detection API video object recognition system of Google open source
- ucore lab6 调度器 实验报告
猜你喜欢
自动化测试中敏捷测试怎么做?
基于485总线的评分系统双机实验报告
MySQL development - advanced query - take a good look at how it suits you
Soft exam information system project manager_ Project set project portfolio management --- Senior Information System Project Manager of soft exam 025
ucore lab8 文件系统 实验报告
DVWA exercise 05 file upload file upload
MySQL数据库(一)
Vysor uses WiFi wireless connection for screen projection_ Operate the mobile phone on the computer_ Wireless debugging -- uniapp native development 008
[Ogg III] daily operation and maintenance: clean up archive logs, register Ogg process services, and regularly back up databases
Express
随机推荐
Don't you even look at such a detailed and comprehensive written software test question?
Capitalize the title of leetcode simple question
Réponses aux devoirs du csapp 7 8 9
How to become a good software tester? A secret that most people don't know
Threads et pools de threads
Face and eye recognition based on OpenCV's own model
Software testing interview summary - common interview questions
软件测试面试要问的性能测试术语你知道吗?
Logstack introduction and deployment -- elasticstack (elk) work notes 019
软件测试行业的未来趋势及规划
Stc-b learning board buzzer plays music 2.0
Practical cases, hand-in-hand teaching you to build e-commerce user portraits | with code
Investment should be calm
China's county life record: go upstairs to the Internet, go downstairs' code the Great Wall '
If the position is absolute, touchablehighlight cannot be clicked - touchablehighlight not clickable if position absolute
Introduction to variable parameters
Knowledge that you need to know when changing to software testing
JDBC introduction
软件测试Bug报告怎么写?
Common Oracle commands