- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1656.java
41 lines (37 loc) · 1.18 KB
/
_1656.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
31
32
33
34
35
36
37
38
39
40
41
packagecom.fishercoder.solutions.secondthousand;
importjava.util.ArrayList;
importjava.util.List;
importjava.util.TreeMap;
publicclass_1656 {
publicstaticclassSolution1 {
publicstaticclassOrderedStream {
TreeMap<Integer, String> map;
intptr;
intlimit;
publicOrderedStream(intn) {
this.map = newTreeMap<>();
this.ptr = 1;
this.limit = n;
}
publicList<String> insert(intid, Stringvalue) {
map.put(id, value);
List<String> result = newArrayList<>();
if (map.containsKey(ptr)) {
for (intkey = ptr; key <= limit; key++) {
if (map.containsKey(key)) {
result.add(map.get(key));
} else {
break;
}
}
inti = id;
while (map.containsKey(i)) {
i++;
}
ptr = i;
}
returnresult;
}
}
}
}