1
class TopVotedCandidate {5
Map<Integer, Integer> voteCount;6
Map<Integer, Integer> voteLead;8
public TopVotedCandidate(int[] persons, int[] times) {9
this.persons = persons;11
length = times.length - 1;14
voteCount = new HashMap<>();15
voteLead = new HashMap<>();16
for (int i = 0; i <= length; i++) {17
int newCount = voteCount.getOrDefault(persons[i], 0) + 1;18
voteCount.put(persons[i], newCount);19
if (newCount >= leadCount) {21
leadPerson = persons[i];23
voteLead.put(times[i], leadPerson);29
if (voteLead.containsKey(t)) {30
leadPerson = voteLead.get(t);31
} else if (t < times[0]) {32
leadPerson = voteLead.get(times[0]);33
} else if (t > times[length]) {34
leadPerson = voteLead.get(times[length]);39
int mid = low + (high - low) / 2;40
if (times[mid] > t) high = mid - 1;43
leadPerson = voteLead.get(times[high]);