Leetcode Note: Go - Maximum Number of Balloons

Maximum Number of Balloons - LeetCode
https://leetcode.com/problems/maximum-number-of-balloons/

  • Go 言語で取り組んだメモ

回答案

[Go] Solution - LeetCode Discuss
https://leetcode.com/problems/maximum-number-of-balloons/discuss/556647/Go-Solution

func maxNumberOfBalloons(text string) int {
    b,a,l,o,n := 0,0,0,0,0
    for _, r := range text{
        switch r{
            case 'b':
                b++
            case 'a':
                a++
            case 'l':
                l++
            case 'o':
                o++
            case 'n':
                n++
        }
    }
    
    res := min(b, min(a,n))
    res = min(res, min(l/2,o/2))
    return res
}

func min(a,b int) int{
    if a < b {
        return a
    }
    
    return b
}