leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0911.cpp (584B)
0 class TopVotedCandidate {
1 map<int, int> um;
3 public:
4 TopVotedCandidate(const vector<int> &persons, const vector<int> ×) {
5 static int votes[5001];
6 int maxi = 0, candid = 0;
8 memset(votes, 0x00, sizeof(votes));
9 for (int i = 0; i < size(persons); i++) {
10 const int crnt = ++votes[persons[i]];
12 if (crnt >= maxi) {
13 candid = persons[i];
14 maxi = crnt;
15 }
17 um[times[i]] = candid;
18 }
19 }
21 int q(int t) const { return prev(um.upper_bound(t))->second; }
22 };