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(key, value, timestamp_prev) was called previously, with timestamp_prev <= timestamp.
  • If there are multiple such values, it returns the one with the largest timestamp_prev.
  • If there are no values, it returns the empty string ("").
Runtime: 212 ms, faster than 55.01% of C++ online submissions for Time Based Key-Value Store.
Memory Usage: 57 MB, less than 100.00% of C++ online submissions for Time Based Key-Value Store.
class TimeMap {
private:
unordered_map<string, map<int, string>> mp;
vector<int> tvec;
public:
/** Initialize your data structure here. */
TimeMap() {} void set(string key, string value, int timestamp) {
mp[key][timestamp] = value;
} string get(string key, int timestamp) {
if(!mp.count(key)) return "";
if(mp[key].count(timestamp)) return mp[key][timestamp];
for(auto it = mp[key].rbegin(); it != mp[key].rend(); it++) {
if(it->first > timestamp) continue;
else {
return it->second;
}
}
return "";
}
};

LC 981. Time Based Key-Value Store的更多相关文章

  1. Leetcode 981. Time Based Key-Value Store(二分查找)

    题目来源:https://leetcode.com/problems/time-based-key-value-store/description/ 标记难度:Medium 提交次数:1/1 代码效率 ...

  2. etcd -> Highly-avaliable key value store for shared configuration and service discovery

    The name "etcd" originated from two ideas, the unix "/etc" folder and "d&qu ...

  3. LeetCode 981. Time Based Key-Value Store

    原题链接在这里:https://leetcode.com/problems/time-based-key-value-store/ 题目: Create a timebased key-value s ...

  4. 【LeetCode】981. Time Based Key-Value Store 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 日期 题目地址:https://leetcod ...

  5. 【leetcode】981. Time Based Key-Value Store

    题目如下: Create a timebased key-value store class TimeMap, that supports two operations. 1. set(string ...

  6. 一些开源搜索引擎实现——倒排使用原始文件,列存储Hbase,KV store如levelDB、mongoDB、redis,以及SQL的,如sqlite或者xxSQL

    本文说明:除开ES,Solr,sphinx系列的其他开源搜索引擎汇总于此.   A search engine based on Node.js and LevelDB A persistent, n ...

  7. Claims Based Authentication and Token Based Authentication和WIF

    基于声明的认证方式,其最大特性是可传递(一方面是由授信的Issuer,即claims持有方,发送到你的应用上,注意信任是单向的.例如QQ集成登录,登录成功后,QQ会向你的应用发送claims.另一方面 ...

  8. External Configuration Store Pattern 外部配置存储模式

    Move configuration information out of the application deployment package to a centralized location. ...

  9. Redis Installation、Configuration、Program Based On Redis Learning

    目录 . Redis 简介 . Redis安装配置 . 编程使用Redis . 使用Lua脚本 1. Redis 简介 0x1: Redis是什么 Redis是一款Nosql类型的基于key-valu ...

随机推荐

  1. X宝个人支付到账

    扫码登录,能看懂的我就不多说了,封了我多少篇文章了!!!!X宝个人到账通知.

  2. IDEA 导入jar包

    项IDEA的项目中导入下载好的jar包: 在intelij IDEA 中,点击File-Project Structure,出现界面的左侧点击Modules,然后点击“+”. 然后找到你要导入的jar ...

  3. POST,PUT和PATCH的区别

    1. GET方法用于获取资源,不应有副作用,所以是幂等的. 比如:GET http://www.bank.com/account/123456,不会改变资源的状态,不论调用一次还是N次都没有副作用.请 ...

  4. Xen 虚拟化技术

    Xen 是一种开源的.属于类型1(裸金属虚拟化,Baremetal Hypervisor)的虚拟化技术,它使多个同样操作系统或不同操作系统的虚拟机运行在同一个物理主机节点上成为可能并实现. Xen 是 ...

  5. 在linux中安装VM tools

    step 1:虚拟机选择安装 Vmware tools ,在DVD中将.tar.gz的文件包拖到桌面中: step 2:打开终端,切换到桌面,cd /home/whoami/桌面 cd /home/u ...

  6. Android.mk走读与Cmake配置

    Android.mk认识: 在上一次[https://www.cnblogs.com/webor2006/p/9946061.html]中学会了用NDK提供的交叉编译工程编译成Android能运行的可 ...

  7. evpp http server定制实现

    evpp http server定制实现 evpp http server定制实现 evpp http server定制实现

  8. Python----常用的__doc__、__name__、__file__的使用

    各自的作用: __doc__:获取到注释内容 __name__:获取到函数的名称 __file__:获取到当前的文件路径 示例代码: #!/usr/bin/env python # -*- codin ...

  9. Web UI开发神器—Kendo UI for jQuery数据管理网格编辑操作

    Kendo UI for jQuery最新试用版下载 Kendo UI目前最新提供Kendo UI for jQuery.Kendo UI for Angular.Kendo UI Support f ...

  10. Matlab step方法

    在Matlab中我们经常能看到Java的影子,即面向对象编程(Object Oriented Programming,OOP). 以Turbo编码为例: hTEnc = comm.TurboEncod ...