当前位置:网站首页>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;
}
}边栏推荐
- It's OK to have hands-on 8 - project construction details 3-jenkins' parametric construction
- 删除所有值为y的元素。数组元素中的值和y的值由主函数通过键盘输入。
- Function: find the approximate value of the limit of the ratio of the former term to the latter term of Fibonacci sequence. For example, when the error is 0.0001, the function value is 0.618056.
- [prefix and notes] prefix and introduction and use
- Future源码一观-JUC系列
- [error record] configure NDK header file path in Visual Studio (three header file paths of NDK | ASM header file path selection related to CPU architecture)
- 在寻求人类智能AI的过程中,Meta将赌注押向了自监督学习
- Regular expression of shell script value
- Software testers, how can you quickly improve your testing skills? Ten minutes to teach you
- 国元证券开户是真的安全可靠吗
猜你喜欢

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,

在寻求人类智能AI的过程中,Meta将赌注押向了自监督学习

手机异步发送短信验证码解决方案-Celery+redis

功能:求出菲波那契数列的前一项与后一项之比的极限的 近似值。例如:当误差为0.0001时,函数值为0.618056。

Struct in linked list

Future source code view -juc series
![[dynamic programming] leetcode 53: maximum subarray sum](/img/f0/80357f9ffc556f3ed4d3aa0901bb1d.jpg)
[dynamic programming] leetcode 53: maximum subarray sum

Release and visualization of related data
![CesiumJS 2022^ 源码解读[8] - 资源封装与多线程](/img/d2/99932660298b4a4cddd7e5e69faca1.png)
CesiumJS 2022^ 源码解读[8] - 资源封装与多线程

GUI application: socket network chat room
随机推荐
What is the future of software testing industry? Listen to the test veterans' answers
It's OK to have hands-on 8 - project construction details 3-jenkins' parametric construction
基于.NetCore开发博客项目 StarBlog - (14) 实现主题切换功能
Is it really possible that the monthly salary is 3K and the monthly salary is 15K?
Day05 表格
Introduction to thread pool
STM32 key light
Makefile judge custom variables
Gauss elimination method and template code
Oracle database knowledge points (IV)
In the process of seeking human intelligent AI, meta bet on self supervised learning
I don't care about you. OKR or KPI, PPT is easy for you
What insurance products should be bought for the elderly?
Fundamentals of machine learning: feature selection with lasso
功能:编写函数fun求s=1^k+2^k +3^k + ......+N^k的值, (1的K次方到N的K次方的累加和)。
PMP 考试常见工具与技术点总结
2-redis architecture design to use scenarios - four deployment and operation modes (Part 2)
老姜的特点
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
Query efficiency increased by 10 times! Three optimization schemes to help you solve the deep paging problem of MySQL