Leetcode Note: Go - Percentage of Letter in String

Percentage of Letter in String - LeetCode
https://leetcode.com/problems/percentage-of-letter-in-string/

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

回答

Go simple one pass easy to understand - Percentage of Letter in String - LeetCode
https://leetcode.com/problems/percentage-of-letter-in-string/solutions/2211680/go-simple-one-pass-easy-to-understand/

func percentageLetter(s string, letter byte) int {
    count := 0
    
    for i := 0; i < len(s); i++ {
        if s[i] == letter {
            count++
        }
    }
    
    return int(float64(count)/float64(len(s)) * 100)
}