Skip to content

Commit d6849cf

Browse files
committed
Runtime: 996 ms (Top 5.13%) | Memory: 131.3 MB (Top 81.29%)
1 parent 8161bd8 commit d6849cf

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

scripts/algorithms/S/Sequentially Ordinal Rank Tracker/Sequentially Ordinal Rank Tracker.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
// Runtime: 996 ms (Top 5.13%) | Memory: 131.3 MB (Top 81.29%)
12
class SORTracker {
23

34
private TreeMap<Integer, List<String>> map;
45
private int queryNum;
5-
6+
67
// Find suitable position for name in the list
78
private int getIndex(String name, List<String> list) {
89
int l = 0, r = list.size() - 1, m = 0;
@@ -16,19 +17,19 @@ private int getIndex(String name, List<String> list) {
1617
}
1718
return name.compareTo(list.get(l)) > 0 ? l+1 : l;
1819
}
19-
20+
2021
public SORTracker() {
2122
map = new TreeMap<>((a,b) -> (b-a));
2223
queryNum = 0;
2324
}
24-
25+
2526
public void add(String name, int score) {
2627
List<String> list = map.getOrDefault(score, new ArrayList<>());
2728
int index = (list.size() == 0) ? 0 : getIndex(name, list);
2829
list.add(index, name);
2930
map.put(score, list);
3031
}
31-
32+
3233
public String get() {
3334
int index = queryNum;
3435
for (int score: map.keySet()) {
@@ -40,4 +41,4 @@ public String get() {
4041
}
4142
return "";
4243
}
43-
}
44+
}

0 commit comments

Comments
 (0)