981. Time Based Key-Value Store

Solution 1:
Store "key, timestamp, value" as HashMap<String, ArrayList<Pair<Integer, String>>>. Call Collections.binarySearch( ) to support get operation
Time complexity of set operation
is and get operation
is
存储为 HashMap<String, ArrayList<Pair<Integer, String>>> 的数据结构,对应为 key: (timestamp, value)。 调用 Collections.binarySearch( ) 完成 get 操作。set 时间复杂度是O(1),get 时间复杂度为 O(lg N)。
Solution 2:
Store "key, timestamp, value" as HashMap<String, TreeMap<Integer, String>>.
Time complexity of set operation
is and get operation
is
存储为 HashMap<String, TreeMap<Integer, String>> 的数据结构,对应为 key: (timestamp: value)。set 和 get 的时间复杂度都是 O(lg N)。
Last updated
Was this helpful?