Map<String, List<Node>> map = new HashMap<>(); /** Initialize your data structure here. */ publicTimeMap(){ } publicvoidset(String key, String value, int timestamp){ List<Node> list = map.getOrDefault(key, new ArrayList<>()); list.add(new Node(key, value, timestamp)); map.put(key,list); } public String get(String key, int timestamp){ List<Node> list = map.getOrDefault(key, new ArrayList<>()); if(list.size() == 0) { return""; } int len = list.size(); int l = 0, r = len - 1; while(l < r) { int mid = l + r + 1 >> 1; if(list.get(mid).t <= timestamp) { l = mid; } else { r = mid - 1; } } return list.get(r).t <= timestamp ? list.get(r).v : ""; } }