leetcode981】的更多相关文章

Create a timebased key-value store class TimeMap, that supports two operations. 1. set(string key, string value, int timestamp) Stores the key and value, along with the given timestamp. 2. get(string key, int timestamp) Returns a value such that set(…
考虑线性的搜索会超时,所以用二叉搜索来解决,代码如下: class TimeMap: def __init__(self): self.ST = dict() def set(self, key: 'str', value: 'str', timestamp: 'int') -> 'None': if key in self.ST.keys(): D = self.ST[key]#dict D.update({timestamp:value}) self.ST.update({key:D}) e…