1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// @Title: 分糖果 (Distribute Candies)
// @Author: 15816537946@163.com
// @Date: 2021-11-01 18:23:47
// @Runtime: 160 ms
// @Memory: 7.3 MB
func distributeCandies(candyType []int) int {
	dict := make(map[int]struct{})
	var cnt int
	for _, v := range candyType {
		if _, ok := dict[v]; !ok {
			dict[v] = struct{}{}
			cnt++
		}
	}
	half := len(candyType) / 2

	length := len(dict)
	if length <= half {
		return length
	}

	return half
}