当前位置:网站首页>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;
}
}
边栏推荐
- Query efficiency increased by 10 times! Three optimization schemes to help you solve the deep paging problem of MySQL
- A Kuan food rushed to the Shenzhen Stock Exchange: with annual sales of 1.1 billion, Hillhouse and Maotai CCB are shareholders
- How to use AHAS to ensure the stability of Web services?
- Is it really possible that the monthly salary is 3K and the monthly salary is 15K?
- MySQL uses the view to report an error, explain/show can not be issued; lacking privileges for underlying table
- Day05 table
- 数据库表外键的设计
- The culprit of unrestrained consumption -- Summary
- [prefix and notes] prefix and introduction and use
- The first training of wechat applet
猜你喜欢
MySQL winter vacation self-study 2022 12 (1)
Beijing invites reporters and media
Gauss elimination method and template code
功能:编写函数fun求s=1^k+2^k +3^k + ......+N^k的值, (1的K次方到N的K次方的累加和)。
Future source code view -juc series
On covariance of array and wildcard of generic type
The FISCO bcos console calls the contract and reports an error does not exist
On the day when 28K joined Huawei testing post, I cried: everything I have done in these five months is worth it
查询效率提升10倍!3种优化方案,帮你解决MySQL深分页问题
Fundamentals of machine learning: feature selection with lasso
随机推荐
Query efficiency increased by 10 times! Three optimization schemes to help you solve the deep paging problem of MySQL
The difference between fetchtype lazy and eagle in JPA
12. Go implementation of integer to Roman numeral and leetcode
Oracle database knowledge points that cannot be learned (III)
Mobile asynchronous sending SMS verification code solution -efficiency+redis
1-redis architecture design to use scenarios - four deployment and operation modes (Part 1)
I don't care about you. OKR or KPI, PPT is easy for you
2022 Software Test Engineer skill list, please check
查询效率提升10倍!3种优化方案,帮你解决MySQL深分页问题
swagger中响应参数为Boolean或是integer如何设置响应描述信息
Function: find the sum of the elements on the main and sub diagonal of the matrix with 5 rows and 5 columns. Note that the elements where the two diagonals intersect are added only once. For example,
Beijing invites reporters and media
中电资讯-信贷业务数字化转型如何从星空到指尖?
Why use get/set instead of exposing properties
Interview script of Software Test Engineer
Alibaba test engineer with an annual salary of 500000 shares notes: a complete set of written tests of software testing
Global and Chinese markets for coronary artery disease treatment devices 2022-2028: Research Report on technology, participants, trends, market size and share
1-Redis架构设计到使用场景-四种部署运行模式(上)
Five high-frequency questions were selected from the 200 questions raised by 3000 test engineers
Is it really possible that the monthly salary is 3K and the monthly salary is 15K?