[Java] Leetcode 981. Time Based Key-Value Store [Binary Search #7]

preview_player
Показать описание
In this video, I'm going to show you how to solve Leetcode 981. Time Based Key-Value Store which is related to Binary Search.

Here’s a quick rundown of what you’re about to learn:

⭐️ Course Contents ⭐️
⌨️ (0:00) Question
⌨️ (03:40) TreeMap Solution
⌨️ (9:17) Binary Search Solution

In the end, you’ll have a really good understanding on how to solve Leetcode 981. Time Based Key-Value Store and questions that are similar to this Binary Search.

Рекомендации по теме
Комментарии
Автор

Set would also be log(n) where n is avg number of timestamps for a key, because inserting a new key into treeMap requires sorting that key ascendingly among existing keys

JerryHou
Автор

Hi Eric, a tip of the set method when using the treemap solution:
public void set(String key, String value, int timestamp) {
map.computeIfAbsent(key, k->new TreeMap<Integer, String>()).put(timestamp, value);
}

MeetManga
Автор

which solution do you recommend the binary search one or the tree map one

chaitanyasharma