leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE | |
commit | 0c6c79eaf07384f8c1aa1c571e240476e5cc0d19 |
parent | b7c7c860e41c8b83baead4883433a1d729d8738b |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Sun, 21 Apr 2024 19:11:42 +0200 |
1 Random Problem
Diffstat:A | Problems/0911.cpp | | | +++++++++++++++++++++++ |
M | README.md | | | + |
2 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/Problems/0911.cpp b/Problems/0911.cpp
@@ -0,0 +1,23 @@
class TopVotedCandidate {
map<int, int> um;
public:
TopVotedCandidate(const vector<int> &persons, const vector<int> ×) {
static int votes[5001];
int maxi = 0, candid = 0;
memset(votes, 0x00, sizeof(votes));
for (int i = 0; i < size(persons); i++) {
const int crnt = ++votes[persons[i]];
if (crnt >= maxi) {
candid = persons[i];
maxi = crnt;
}
um[times[i]] = candid;
}
}
int q(int t) const { return prev(um.upper_bound(t))->second; }
};
diff --git a/README.md b/README.md
@@ -545,6 +545,7 @@ for solving problems.
| 0905 | Easy | [Sort Array By Parity](Problems/0905.cpp) |
| 0907 | Medium | [Sum of Subarray Minimums](Problems/0907.cpp) |
| 0909 | Medium | [Snakes and Ladders](Problems/0909.cpp) |
| 0911 | Medium | [Online Election](Problems/0911.cpp) |
| 0912 | Medium | [Sort an Array](Problems/0912.cpp) |
| 0915 | Medium | [Partition Array into Disjoint Intervals](Problems/0915.cpp) |
| 0916 | Medium | [Word Subsets](Problems/0916.cpp) |