当前位置:网站首页>Force buckle 1189 Maximum number of "balloons"
Force buckle 1189 Maximum number of "balloons"
2022-07-06 12:29:00 【Yangshiwei....】
subject :
analysis :
First of all, you should count all the times of the relevant letters of the balloon word , Then we found that in this word ,l and o It appears twice , The others only appeared once , So we divide them 2 Rounding down , Then find out the minimum value of five words .
Code :
class Solution {
public int maxNumberOfBalloons(String text) {
int [] a=new int[5];
for(int i=0;i<text.length();i++){
char c=text.charAt(i);
if(c=='b'){
a[0]++;
}
if(c=='a'){
a[1]++;
}
if(c=='l'){
a[2]++;
}
if(c=='o'){
a[3]++;
}
if(c=='n'){
a[4]++;
}
}
a[2]/=2;
a[3]/=2;
return min(a[0],a[1],a[2],a[3],a[4]);
}
public int min(int a,int b,int c,int d,int e){
if(a>b){
a=b;
}
if(a>c){
a=c;
}
if(a>d){
a=d;
}
if(a>e){
a=e;
}
return a;
}
}
边栏推荐
猜你喜欢
MySQL時間、時區、自動填充0的問題
程序员老鸟都会搞错的问题 C语言基础 指针和数组
Mp3mini playback module Arduino < dfrobotdfplayermini H> function explanation
Amba, ahb, APB, Axi Understanding
VSCode基础配置
Problèmes avec MySQL time, fuseau horaire, remplissage automatique 0
ES6 grammar summary -- Part I (basic)
js 变量作用域和函数的学习笔记
[Nodejs] 20. Koa2 onion ring model ----- code demonstration
Compilation principle: preprocessing of source program and design and implementation of lexical analysis program (including code)
随机推荐
记一次云服务器被密码爆破的经历——关小黑屋、改密码、改端口
Compilation principle: preprocessing of source program and design and implementation of lexical analysis program (including code)
MySQL時間、時區、自動填充0的問題
Expected value (EV)
[leetcode15] sum of three numbers
Esp8266 connect onenet (old mqtt mode)
[offer9]用两个栈实现队列
Important methods of array and string
Redis based distributed locks and ultra detailed improvement ideas
ARM PC=PC+8 最便于理解的阐述
JS正则表达式基础知识学习
AMBA、AHB、APB、AXI的理解
Basic operations of databases and tables ----- modifying data tables
Unity3D制作注册登录界面,并实现场景跳转
JS變量類型以及常用類型轉換
Basic operations of databases and tables ----- creating data tables
VSCode基础配置
JS变量类型以及常用类型转换
Kconfig Kbuild
Arduino uno R3 register writing method (1) -- pin level state change