-
-
Notifications
You must be signed in to change notification settings - Fork 9k
/
Copy pathSolution2.java
30 lines (26 loc) · 991 Bytes
/
Solution2.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class SORTracker {
private PriorityQueue<Map.Entry<Integer, String>> good = new PriorityQueue<>(
(a, b)
-> a.getKey().equals(b.getKey()) ? b.getValue().compareTo(a.getValue())
: a.getKey() - b.getKey());
private PriorityQueue<Map.Entry<Integer, String>> bad = new PriorityQueue<>(
(a, b)
-> a.getKey().equals(b.getKey()) ? a.getValue().compareTo(b.getValue())
: b.getKey() - a.getKey());
public SORTracker() {
}
public void add(String name, int score) {
good.offer(Map.entry(score, name));
bad.offer(good.poll());
}
public String get() {
good.offer(bad.poll());
return good.peek().getValue();
}
}
/**
* Your SORTracker object will be instantiated and called as such:
* SORTracker obj = new SORTracker();
* obj.add(name,score);
* String param_2 = obj.get();
*/