strings.Fields拆分单词,然后用map[string]int直接统计,主要代码:
1 func WordCount(s string) map[string]int { 2 fields := strings.Fields(s) 3 result := make(map[string]int) 4 for _, field := range fields { 5 result[field] += 1 6 } 7 return result 8 }
标签:map,string,int,Maps,result,Exercise From: https://www.cnblogs.com/wxiong/p/17606994.html