Shawn's Blog

  • Home
  • Tags
  • Categories
  • Archives
  • Search
  • Table of Contents
  • Overview

Shawn

若有恒,何必三更眠五更起;最无益,莫过一日曝十日寒。
392 posts
13 categories
114 tags

LeetCode 781. Rabbits in Forest

Posted on 2021-04-04 Edited on 2024-11-24 In LeetCode
1
2
3
4
5
6
7
8
9
10
11
12
class 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;
}
};
# Math# Hash Table
LeetCode 1143. Longest Common Subsequence
LeetCode 88. Merge Sorted Array
© 2024 Shawn
Powered by Hexo & NexT.Mist
0%