当前位置:网站首页>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;
}
}边栏推荐
- 【.NET+MQTT】. Net6 environment to achieve mqtt communication, as well as bilateral message subscription and publishing code demonstration of server and client
- Introduction to thread pool
- Att & CK actual combat series - red team actual combat - V
- 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?
- 机器学习基础:用 Lasso 做特征选择
- [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)
- Oracle database knowledge points (I)
- Global and Chinese market of underwater bags 2022-2028: Research Report on technology, participants, trends, market size and share
- Leetcode 121 best time to buy and sell stock (simple)
猜你喜欢

Introduction to A-frame virtual reality development

1-Redis架构设计到使用场景-四种部署运行模式(上)

CLP information - how does the digital transformation of credit business change from star to finger?

Print diamond pattern
![[error record] configure NDK header file path in Visual Studio](/img/9f/89f68c037dcf68a31a2de064dd8471.jpg)
[error record] configure NDK header file path in Visual Studio

What is the GPM scheduler for go?

Generic

The difference between objects and objects

What is the potential of pocket network, which is favored by well-known investors?

MySQL winter vacation self-study 2022 12 (1)
随机推荐
Self study software testing. To what extent can you go out and find a job?
Oracle database knowledge points (IV)
不得不会的Oracle数据库知识点(三)
7.1 learning content
功能:求出菲波那契数列的前一项与后一项之比的极限的 近似值。例如:当误差为0.0001时,函数值为0.618056。
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
Delete all elements with a value of Y. The values of array elements and y are entered by the main function through the keyboard.
The difference between fetchtype lazy and eagle in JPA
长文综述:大脑中的熵、自由能、对称性和动力学
[common error] UART cannot receive data error
Eight year test old bird, some suggestions for 1-3 year programmers
Introduction to thread pool
What is the GPM scheduler for go?
The FISCO bcos console calls the contract and reports an error does not exist
The super fully automated test learning materials sorted out after a long talk with a Tencent eight year old test all night! (full of dry goods
[dynamic programming] leetcode 53: maximum subarray sum
About uintptr_ T and IntPtr_ T type
Software testers, how can you quickly improve your testing skills? Ten minutes to teach you
Is the securities account opened by Caicai for individuals safe? Is there a routine
删除所有值为y的元素。数组元素中的值和y的值由主函数通过键盘输入。