LeetCode 781. Rabbits in Forest Posted on 2021-04-04 Edited on 2024-11-24 In LeetCode 123456789101112class Solution {public: int numRabbits(vector<int>& answers) { unordered_map<int, int> m; for (int y : answers) ++m[y]; int ans = 0; for (auto &[y, x] : m) ans += (x + y) / (y + 1) * (y + 1); return ans; }};