1# Runtime: 54 ms (Top 35.1%) | Memory: 16.38 MB (Top 76.8%)234class Solution:5def numRabbits(self, answers: List[int]) -> int:6counts = {}7count = 089for answer in answers:10if answer == 0:11# This must be the only rabbit of its color.12count += 113elif answer not in counts or counts[answer] == 0:14# This is the first time the color appears.15counts[answer] = 116# Add all rabbits having this new color.17count += answer + 118else:19# Add one to how many times answer occurred.20counts[answer] += 121if counts[answer] > answer:22# If n+1 rabbits have said n,23# this color group is complete.24counts[answer] = 02526return count