Re: [閒聊] 每日LeetCode已回收

看板Marginalman作者 (愛麗絲)時間3年前 (2022/10/06 15:02), 編輯推噓0(111)
留言3則, 3人參與, 3年前最新討論串33/719 (看更多)
981. Time Based Key-Value Store 這幾天的每日一題都比較直觀(無聊) class TimeMap { public: unordered_map<string, vector<pair<int,string>>> M; TimeMap() {} void set(string key, string value, int timestamp) { M[key].push_back({timestamp, value}); } string get(string key, int timestamp) { const pair<int, string> pivot{timestamp, "fxfxxxfxx"}; constexpr auto cmp = [](decltype(pivot) a, decltype(pivot) b) { return a.first > b.first; }; auto it = lower_bound(M[key].rbegin(), M[key].rend(), pivot, cmp); return (it == M[key].rend()) ? "" : it->second; } }; 有點醜,不過隨便喇 倒著用std::lower_bound() -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.112.16.175 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1665039776.A.CA5.html

10/06 15:03, 3年前 , 1F
好好喔 都有酷酷的函式庫
10/06 15:03, 1F

10/06 15:05, 3年前 , 2F
跨謀啦
10/06 15:05, 2F

10/06 15:12, 3年前 , 3F
大師
10/06 15:12, 3F
文章代碼(AID): #1ZFdsWob (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1ZFdsWob (Marginalman)