luoheng
10/7/2019 - 8:33 AM

maxNumberOfBalloons

func maxNumberOfBalloons(text string) int {
    hash := [26]int{}
    for _, c := range text {
        hash[c-'a']++
    }
    sum := hash[1] // b
    if sum > hash[0] { // a
        sum = hash[0]
    }
    if sum > hash[11] / 2 { // l
        sum = hash[11] / 2
    }
    if sum > hash[14] / 2 { // o
        sum = hash[14] / 2
    }
    if sum > hash[13] { // n
        sum = hash[13]
    }
    return sum
}