mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
d9b9bbd4f5
The for loop utilized in 283 was improperly structured as 'start' was no declared as the value to index. Also, make the other cases more readable. Signed-off-by: RJ Trujillo <certifiedblyndguy@gmail.com>
39 lines
1014 B
C
39 lines
1014 B
C
int maxNumberOfBalloons(char * text){
|
|
/*
|
|
0 -> b,
|
|
1 -> a,
|
|
2 -> l,
|
|
3 -> o,
|
|
4 -> n
|
|
*/
|
|
int count_letters[5] = {0};
|
|
int i, min_counter_ballons;
|
|
|
|
for (char *ptr = text; *ptr; ptr++) {
|
|
if (*ptr == 'b') {
|
|
count_letters[0]++;
|
|
} else if(*ptr == 'a') {
|
|
count_letters[1]++;
|
|
} else if (*ptr == 'l') {
|
|
count_letters[2]++;
|
|
} else if(*ptr == 'o') {
|
|
count_letters[3]++;
|
|
} else if(*ptr == 'n') {
|
|
count_letters[4]++;
|
|
}
|
|
}
|
|
|
|
/* Divide by 2 the repeted letters */
|
|
count_letters[2] /= 2;
|
|
count_letters[3] /= 2;
|
|
|
|
/* Max number of times which we can write ballon is equal to min value of letters on count_letter */
|
|
min_counter_ballons = count_letters[0];
|
|
for (i = 1; i < 5; i++) {
|
|
if (count_letters[i] < min_counter_ballons)
|
|
min_counter_ballons = count_letters[i];
|
|
}
|
|
|
|
return min_counter_ballons;
|
|
}
|