Re: [閒聊] 每日LeetCode已回收
→
10/06 10:34,
10/06 10:34
→
10/06 10:35,
10/06 10:35
機掰 Java要自己造輪子= =
class TimeMap {
Map<String, List<Integer>> timeMap;
Map<String, List<String>> valMap;
public TimeMap() {
this.timeMap = new HashMap<>();
this.valMap = new HashMap<>();
}
public void set(String key, String value, int timestamp) {
if (!timeMap.containsKey(key)) {
timeMap.put(key, new ArrayList<>());
valMap.put(key, new ArrayList<>());
}
timeMap.get(key).add(timestamp);
valMap.get(key).add(value);
}
public String get(String key, int timestamp) {
if (!timeMap.containsKey(key) || timeMap.get(key).get(0) > timestamp)
return "";
List<Integer> times = timeMap.get(key);
int l = 0, r = times.size();
while (l < r) {
int m = (l + r) >> 1;
if (times.get(m) <= timestamp)
l = m + 1;
else
r = m;
}
return valMap.get(key).get(l - 1);
}
}
--
https://i.imgur.com/xDr11uL.jpg

--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.160.44.149 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1665024817.A.9D4.html
推
10/06 10:54,
3年前
, 1F
10/06 10:54, 1F
→
10/06 10:57,
3年前
, 2F
10/06 10:57, 2F
→
10/06 11:13,
3年前
, 3F
10/06 11:13, 3F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 32 之 719 篇):