qiyuangong / leetcode

Python & JAVA Solutions for Leetcode
MIT License
5.23k stars 1.49k forks source link

Create 1189_Maximum_Number_of_Balloons.java #52

Closed ChesterChangLiu closed 2 years ago

javadev commented 2 years ago

The alternative solution

public class Solution {
    public int maxNumberOfBalloons(String text) {
        int[] counts = new int[26];
        for (char c : text.toCharArray()) {
            counts[c - 'a']++;
        }
        return Math.min(
                counts[0],
                Math.min(
                        counts[1], Math.min(counts[11] / 2, Math.min(counts[14] / 2, counts[13]))));
    }
}
qiyuangong commented 2 years ago

LGTM Thank you for your contribution @ChesterChangLiu @javadev !