LeetCodeDiary

A Diary for solving LeetCode problems

View on GitHub
class Solution:
    def numRabbits(self, answers: List[int]) -> int:
        count = Counter(answers)
        ans = sum((x + y) // (y + 1) * (y + 1) for y, x in count.items())
        return ans

哈希 中等 复活节特辑

https://leetcode-cn.com/problems/rabbits-in-forest/