Leetcode Note: Go - Counting Words With a Given Prefix

Counting Words With a Given Prefix - LeetCode
https://leetcode.com/problems/counting-words-with-a-given-prefix/

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

回答

✅2185. Counting Words With a Given Prefix - Counting Words With a Given Prefix - LeetCode
https://leetcode.com/problems/counting-words-with-a-given-prefix/solutions/3378955/2185-counting-words-with-a-given-prefix/

func prefixCount(words []string, pref string) (cnt int) {
	for _, w := range words {
		if len(w) >= len(pref) && w[:len(pref)] == pref {
			cnt += 1
		}
	}
	return
}