Skip to content

Commit 96ab6f3

Browse files
add 981
1 parent 9f01518 commit 96ab6f3

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ _If you like this project, please leave me a star._ ★
282282
|1003|[Check If Word Is Valid After Substitutions](https://leetcode.com/problems/check-if-word-is-valid-after-substitutions/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1003.java) | |Medium|
283283
|1002|[Find Common Characters](https://leetcode.com/problems/find-common-characters/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1002.java) | |Easy|
284284
|999|[Available Captures for Rook](https://leetcode.com/problems/available-captures-for-rook/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_999.java) | |Easy|
285+
|981|[Time Based Key-Value Store](https://leetcode.com/problems/time-based-key-value-store/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_981.java) | |Medium|
285286
|997|[Find the Town Judge](https://leetcode.com/problems/find-the-town-judge/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_997.java) | |Easy|
286287
|994|[Rotting Oranges](https://leetcode.com/problems/rotting-oranges/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_994.java) | |Easy| BFS
287288
|993|[Cousins in Binary Tree](https://leetcode.com/problems/cousins-in-binary-tree/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_993.java) | |Easy| Tree, BFS
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
import java.util.TreeMap;
6+
7+
public class _981 {
8+
public static class Solution1 {
9+
10+
public static class TimeMap {
11+
12+
Map<String, TreeMap<Integer, String>> map;
13+
14+
/**
15+
* Initialize your data structure here.
16+
*/
17+
public TimeMap() {
18+
this.map = new HashMap<>();
19+
}
20+
21+
public void set(String key, String value, int timestamp) {
22+
if (!map.containsKey(key)) {
23+
map.put(key, new TreeMap<>());
24+
}
25+
TreeMap<Integer, String> timestampMap = map.get(key);
26+
timestampMap.put(timestamp, value);
27+
}
28+
29+
public String get(String key, int timestamp) {
30+
TreeMap<Integer, String> timestampMap = map.get(key);
31+
Integer prevTimestamp = timestampMap.floorKey(timestamp);
32+
if (prevTimestamp == null) {
33+
return "";
34+
} else {
35+
return timestampMap.get(prevTimestamp);
36+
}
37+
}
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy