Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit96ab6f3

Browse files
add 981
1 parent9f01518 commit96ab6f3

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+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.HashMap;
4+
importjava.util.Map;
5+
importjava.util.TreeMap;
6+
7+
publicclass_981 {
8+
publicstaticclassSolution1 {
9+
10+
publicstaticclassTimeMap {
11+
12+
Map<String,TreeMap<Integer,String>>map;
13+
14+
/**
15+
* Initialize your data structure here.
16+
*/
17+
publicTimeMap() {
18+
this.map =newHashMap<>();
19+
}
20+
21+
publicvoidset(Stringkey,Stringvalue,inttimestamp) {
22+
if (!map.containsKey(key)) {
23+
map.put(key,newTreeMap<>());
24+
}
25+
TreeMap<Integer,String>timestampMap =map.get(key);
26+
timestampMap.put(timestamp,value);
27+
}
28+
29+
publicStringget(Stringkey,inttimestamp) {
30+
TreeMap<Integer,String>timestampMap =map.get(key);
31+
IntegerprevTimestamp =timestampMap.floorKey(timestamp);
32+
if (prevTimestamp ==null) {
33+
return"";
34+
}else {
35+
returntimestampMap.get(prevTimestamp);
36+
}
37+
}
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp