mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-04 16:12:47 +08:00
15 lines
202 B
Go
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
|
|
}
|