leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE | |
commit | 61cbebf2c36bcaf515c4336bfd3df65072040435 |
parent | 0e05b9b95b1528c636d7dd850bddddc033414018 |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Sun, 4 Feb 2024 22:44:41 +0000 |
1 Random Problem
Diffstat:A | Problems/0781.cpp | | | ++++++++++++++++++++ |
M | README.md | | | + |
2 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/Problems/0781.cpp b/Problems/0781.cpp
@@ -0,0 +1,20 @@
class Solution {
static const int size = 1001;
public:
int numRabbits(const vector<int> &answers) const {
int count[size];
memset(count, 0x00, sizeof(count));
for (const int n : answers)
count[n]++;
int res = count[0];
for (int i = 1; i < size; i++) {
if (!count[i]) continue;
res += ((count[i] + i) / (i + 1)) * (i + 1);
}
return res;
}
};
diff --git a/README.md b/README.md
@@ -464,6 +464,7 @@ for solving problems.
| 0767 | Medium | [Reorganize String](Problems/0767.cpp) |
| 0769 | Medium | [Max Chunks To Make Sorted](Problems/0769.cpp) |
| 0779 | Medium | [K-th Symbol in Grammar](Problems/0779.cpp) |
| 0781 | Medium | [Rabbits in Forest](Problems/0781.cpp) |
| 0783 | Easy | [Minimum Distance Between BST Nodes](Problems/0783.cpp) |
| 0784 | Medium | [Letter Case Permutation](Problems/0784.cpp) |
| 0785 | Medium | [Is Graph Bipartite?](Problems/0785.cpp) |