mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 16:36:41 +08:00
14 lines
245 B
Go
14 lines
245 B
Go
package leetcode
|
|
|
|
func distributeCandies(candies []int) int {
|
|
n, m := len(candies), make(map[int]struct{}, len(candies))
|
|
for _, candy := range candies {
|
|
m[candy] = struct{}{}
|
|
}
|
|
res := len(m)
|
|
if n/2 < res {
|
|
return n / 2
|
|
}
|
|
return res
|
|
}
|