Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TimeMap:
- def __init__(self):
- self.hashmap = defaultdict(list)
- def set(self, key: str, value: str, timestamp: int) -> None:
- self.hashmap[key].append([value, timestamp])
- def get(self, key: str, timestamp: int) -> str:
- if key not in self.hashmap:
- return ""
- ans = ""
- store = self.hashmap[key]
- low, high = 0, len(store) - 1
- while low <= high:
- mid = (low + high)//2
- if store[mid][1] <= timestamp:
- ans = store[mid][0]
- low = mid + 1
- else:
- high = mid - 1
- return ans
- # Your TimeMap object will be instantiated and called as such:
- # obj = TimeMap()
- # obj.set(key,value,timestamp)
- # param_2 = obj.get(key,timestamp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement