当前位置:网站首页>Force deduction solution summary 1189- maximum number of "balloons"
Force deduction solution summary 1189- maximum number of "balloons"
2022-07-04 00:58:00 【Lost summer】
Original link : Power button
describe :
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 1:
Input :text = "nlaebolko"
Output :1
Example 2:
Input :text = "loonbalxballpoon"
Output :2
Example 3:
Input :text = "leetcode"
Output :0
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/maximum-number-of-balloons
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Their thinking :
* Their thinking : * Use an array to store 'a' To 'z' this 26 Letters . And then judge a,b,l/2,o/2,n The minimum of these numbers is good .
Code :
public class Solution1189 {
public int maxNumberOfBalloons(String text) {
char[] chars = text.toCharArray();
int[] ints = new int[26];
for (int i = 0; i < chars.length; i++) {
char aChar = chars[i];
ints[aChar - 'a']++;
}
int min = Math.min(ints[0], ints['b' - 'a']);
min = Math.min(min, ints['l' - 'a'] / 2);
min = Math.min(min, ints['o' - 'a'] / 2);
min = Math.min(min, ints['n' - 'a']);
return min;
}
}边栏推荐
- Severity code description the project file line prohibits the display of status error c4996 fopen ('fscanf ', StrCmp): this function or variable may be unsafe The most comprehensive solution
- OS interrupt mechanism and interrupt handler
- A Kuan food rushed to the Shenzhen Stock Exchange: with annual sales of 1.1 billion, Hillhouse and Maotai CCB are shareholders
- Bodong medical sprint Hong Kong stocks: a 9-month loss of 200million Hillhouse and Philips are shareholders
- The FISCO bcos console calls the contract and reports an error does not exist
- 中电资讯-信贷业务数字化转型如何从星空到指尖?
- Future源码一观-JUC系列
- Oracle database knowledge points (I)
- I don't care about you. OKR or KPI, PPT is easy for you
- Struct in linked list
猜你喜欢

功能:将主函数中输入的字符串反序存放。例如:输入字符串“abcdefg”,则应输出“gfedcba”。

Analysis and solution of lazyinitializationexception

中电资讯-信贷业务数字化转型如何从星空到指尖?

Beijing invites reporters and media

AI helps make new breakthroughs in art design plagiarism retrieval! Professor Liu Fang's team paper was employed by ACM mm, a multimedia top-level conference

长文综述:大脑中的熵、自由能、对称性和动力学

Windos10 reinstallation system tutorial

基于.NetCore开发博客项目 StarBlog - (14) 实现主题切换功能

I don't care about you. OKR or KPI, PPT is easy for you

@EnableAsync @Async
随机推荐
Leetcode 121 best time to buy and sell stock (simple)
Function: store the strings entered in the main function in reverse order. For example, if you input the string "ABCDEFG", you should output "gfedcba".
Long article review: entropy, free energy, symmetry and dynamics in the brain
Severity code description the project file line prohibits the display of status error c4996 fopen ('fscanf ', StrCmp): this function or variable may be unsafe The most comprehensive solution
Beijing invites reporters and media
What is the GPM scheduler for go?
Eight year test old bird, some suggestions for 1-3 year programmers
Makefile judge custom variables
The frost peel off the purple dragon scale, and the xiariba people will talk about database SQL optimization and the principle of indexing (primary / secondary / clustered / non clustered)
STM32 key light
打印菱形图案
Gauss elimination method and template code
MPLS experiment
Introduction to unity shader essentials reading notes Chapter III unity shader Foundation
Optimization of for loop
Global and Chinese market of underwater bags 2022-2028: Research Report on technology, participants, trends, market size and share
Function: write function fun to find s=1^k+2^k +3^k ++ The value of n^k, (the cumulative sum of the K power of 1 to the K power of n).
Technical practice online fault analysis and solutions (Part 1)
Global and Chinese markets for coronary artery disease treatment devices 2022-2028: Research Report on technology, participants, trends, market size and share
Delete all elements with a value of Y. The values of array elements and y are entered by the main function through the keyboard.