forked from Google-DSC-TMSL/ProjectAlgorithms
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimebasedkeyvaluestore.java
More file actions
Latest commit
28 lines (24 loc) · 738 Bytes
/
Copy pathtimebasedkeyvaluestore.java
File metadata and controls
28 lines (24 loc) · 738 Bytes
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
publicclassSolution {
privateMap<String,TreeMap<Integer,String>> map;
/** Initialize your data structure here. */
publicTimeMap() {
map = newHashMap<>();
}
publicvoidset(Stringkey, Stringvalue, inttimestamp) {
if(!map.containsKey(key)) {
map.put(key,newTreeMap<>());
}
map.get(key).put(timestamp,value);
}
publicStringget(Stringkey, inttimestamp) {
TreeMap<Integer,String> treeMap = map.get(key);
if(treeMap==null) {
return"";
}
Integerfloor = treeMap.floorKey(timestamp);
if(floor==null) {
return"";
}
returntreeMap.get(floor);
}
}