当前位置:网站首页>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;
}
}
边栏推荐
- 查询效率提升10倍!3种优化方案,帮你解决MySQL深分页问题
- What is regression testing? Talk about regression testing in the eyes of Ali Test Engineers
- gslb(global server load balance)技术的一点理解
- 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)
- 国元证券开户是真的安全可靠吗
- Oracle database knowledge points that cannot be learned (II)
- 手机异步发送短信验证码解决方案-Celery+redis
- Data mining vs Machine Learning: what is the difference between them? Which is more suitable for you to learn
- Future源码一观-JUC系列
- 2-Redis架构设计到使用场景-四种部署运行模式(下)
猜你喜欢
A-Frame虚拟现实开发入门
GUI 应用:socket 网络聊天室
Print diamond pattern
CLP information - how does the digital transformation of credit business change from star to finger?
机器学习基础:用 Lasso 做特征选择
功能:将主函数中输入的字符串反序存放。例如:输入字符串“abcdefg”,则应输出“gfedcba”。
What is the GPM scheduler for go?
(Introduction to database system | Wang Shan) Chapter V database integrity: Exercises
Regular expression of shell script value
Windos10 reinstallation system tutorial
随机推荐
Alibaba test engineer with an annual salary of 500000 shares notes: a complete set of written tests of software testing
Function: store the strings entered in the main function in reverse order. For example, if you input the string "ABCDEFG", you should output "gfedcba".
The difference between fetchtype lazy and eagle in JPA
What insurance products should be bought for the elderly?
PMP 考试常见工具与技术点总结
On covariance of array and wildcard of generic type
12. Go implementation of integer to Roman numeral and leetcode
Release and visualization of related data
[prefix and notes] prefix and introduction and use
MPLS experiment
Cloud dial test helps Weidong cloud education to comprehensively improve the global user experience
Design of database table foreign key
Weekly open source project recommendation plan
【.NET+MQTT】. Net6 environment to achieve mqtt communication, as well as bilateral message subscription and publishing code demonstration of server and client
Makefile judge custom variables
【.NET+MQTT】. Net6 environment to achieve mqtt communication, as well as bilateral message subscription and publishing code demonstration of server and client
[dynamic programming] leetcode 53: maximum subarray sum
Software testers, how can you quickly improve your testing skills? Ten minutes to teach you
Summary of common tools and technical points of PMP examination
Delete all elements with a value of Y. The values of array elements and y are entered by the main function through the keyboard.