1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
// @Title: 统计包含给定前缀的字符串 (Counting Words With a Given Prefix)
// @Author: 15816537946@163.com
// @Date: 2022-02-27 10:31:41
// @Runtime: 4 ms
// @Memory: 3.4 MB

func prefixCount(words []string, pref string) int {
    var cnt int
    for _, v := range words {
        if strings.HasPrefix(v, pref) {
            cnt++
        }
    }
    return cnt
}