// Map函数:接收文本片段,返回单词计数的map func Map(text string) map[string]int { wordCount := make(map[string]int) words := strings.Fields(text) // 分割单词 for _, word := range words { wordCount[word]++ } return wordCount } // Reduce函数:合并多个map中的计数 func Reduce(maps []map[string]int) map[string]int { result := make(map[string]int) for _, m := range maps { for word, count := range m { result[word] += count } } return result } 他想要这样的吗?
2 1

相关推荐

牛客网
牛客企业服务