代码拉取完成,页面将自动刷新
# Time: set: O(1)
# get: O(logn)
# Space: O(n)
import collections
import bisect
class TimeMap(object):
def __init__(self):
"""
Initialize your data structure here.
"""
self.lookup = collections.defaultdict(list)
def set(self, key, value, timestamp):
"""
:type key: str
:type value: str
:type timestamp: int
:rtype: None
"""
self.lookup[key].append((timestamp, value))
def get(self, key, timestamp):
"""
:type key: str
:type timestamp: int
:rtype: str
"""
A = self.lookup.get(key, None)
if A is None:
return ""
i = bisect.bisect_right(A, (timestamp+1, 0))
return A[i-1][1] if i else ""
# Your TimeMap object will be instantiated and called as such:
# obj = TimeMap()
# obj.set(key,value,timestamp)
# param_2 = obj.get(key,timestamp)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。