aboutsummaryrefslogtreecommitdiffstats
path: root/1160/main.go
blob: 84e9c21f82f61e26b97fd01661319a9ec4bb9126 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package main

func countCharacters(words []string, chars string) int {
	var cnt int
	charMap := make(map[rune]int)
	for _, v := range chars {
		charMap[v]++
	}
	for _, v := range words {
		tmpMap := make(map[rune]int)
		for _, vv := range v {
			tmpMap[vv]++
		}
		var flag bool
		for k, v := range tmpMap {
			if charMap[k] < v {
				flag = true
				break
			}
		}
		if !flag {
			cnt += len(v)
		}
	}
	return cnt
}