当前位置:网站首页>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;
}
}边栏推荐
- 12. Go implementation of integer to Roman numeral and leetcode
- Att & CK actual combat series - red team actual combat - V
- Anomalies seen during the interview
- 2-redis architecture design to use scenarios - four deployment and operation modes (Part 2)
- Generic
- How to be a professional software testing engineer? Listen to the byte five year old test
- Analysis and solution of lazyinitializationexception
- Gauss elimination method and template code
- Makefile judge custom variables
- 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

Att & CK actual combat series - red team actual combat - V

Struct in linked list

The FISCO bcos console calls the contract and reports an error does not exist

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

It's OK to have hands-on 8 - project construction details 3-jenkins' parametric construction

Introduction to A-frame virtual reality development

Self study software testing. To what extent can you go out and find a job?

Sequence list and linked list
![CesiumJS 2022^ 源码解读[8] - 资源封装与多线程](/img/d2/99932660298b4a4cddd7e5e69faca1.png)
CesiumJS 2022^ 源码解读[8] - 资源封装与多线程
随机推荐
gslb(global server load balance)技术的一点理解
[error record] configure NDK header file path in Visual Studio
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).
The first training of wechat applet
Cloud dial test helps Weidong cloud education to comprehensively improve the global user experience
The FISCO bcos console calls the contract and reports an error does not exist
Bodong medical sprint Hong Kong stocks: a 9-month loss of 200million Hillhouse and Philips are shareholders
Weekly open source project recommendation plan
What is the future of software testing industry? Listen to the test veterans' answers
Employees' turnover intention is under the control of the company. After the dispute, the monitoring system developer quietly removed the relevant services
Future source code view -juc series
Struct in linked list
Anomalies seen during the interview
Characteristics of ginger
[software testing] you haven't mastered these real interview questions of big companies?
Global and Chinese market of underwater bags 2022-2028: Research Report on technology, participants, trends, market size and share
技術實踐|線上故障分析及解决方法(上)
【.NET+MQTT】. Net6 environment to achieve mqtt communication, as well as bilateral message subscription and publishing code demonstration of server and client
Release and visualization of related data
Is it really possible that the monthly salary is 3K and the monthly salary is 15K?