Files
LeetCode-Go/leetcode/0781.Rabbits-in-Forest/781. Rabbits in Forest.go
2020-08-07 17:06:53 +08:00

15 lines
202 B
Go

package leetcode
func numRabbits(ans []int) int {
total, m := 0, make(map[int]int)
for _, v := range ans {
if m[v] == 0 {
m[v] += v
total += v + 1
} else {
m[v]--
}
}
return total
}