class MyHashMap {
public:
vector<int> hashMap;
/** Initialize your data structure here. */
MyHashMap() { } /** value will always be non-negative. */
void put(int key, int value) {
if(key>=hashMap.size()) {
for(int i=hashMap.size();i<=key;i++) hashMap.push_back(-);
}
hashMap[key]=value;
} /** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */
int get(int key) {
if(key>=hashMap.size()) return -;
return hashMap[key];
} /** Removes the mapping of the specified value key if this map contains a mapping for the key */
void remove(int key) {
if(key>=hashMap.size()) return;
hashMap[key]=-;
}
};

leetcode706的更多相关文章

  1. [Swift]LeetCode706. 设计哈希映射 | Design HashMap

    Design a HashMap without using any built-in hash table libraries. To be specific, your design should ...

  2. LeetCode706. Design HashMap

    题目  不使用任何内建的哈希表库设计一个哈希映射 具体地说,你的设计应该包含以下的功能 put(key, value):向哈希映射中插入(键,值)的数值对.如果键对应的值已经存在,更新这个值. get ...

  3. Leetcode706.Design HashMap设计哈希映射

    不使用任何内建的哈希表库设计一个哈希映射 具体地说,你的设计应该包含以下的功能 put(key, value):向哈希映射中插入(键,值)的数值对.如果键对应的值已经存在,更新这个值. get(key ...

随机推荐

  1. 【javascript】js处理字符串

    javascript常用方法锦集: 处理字符串 在Javascript除了使用数组和对象 String.replace(regexp | replaceThis,replaceWith |callba ...

  2. SQL Server, Cannot resolve the collation conflict

    今天遇到一个较为头痛的问题: Cannot resolve the collation conflict between "Chinese_PRC_90_CI_AS" and &q ...

  3. bzoj 4852 炸弹攻击

    bzoj 4852 炸弹攻击 二维平面上的最优解问题,模拟退火是一个较为优秀的近似算法. 此题确定圆心后,便可 \(O(m)\) 算出收益,且最优解附近显然也较优,是连续变化的,可以直接模拟退火. 小 ...

  4. JanusGraph Server配置

    转自:https://www.cnblogs.com/jiyuqi/p/320267ff0b5052fad4613945e58ea1f1.html JanusGraph使用Gremlin Server ...

  5. LeetCode 675. Cut Off Trees for Golf Event

    原题链接在这里:https://leetcode.com/problems/cut-off-trees-for-golf-event/description/ 题目: You are asked to ...

  6. LeetCode Number of Atoms

    原题链接在这里:https://leetcode.com/problems/number-of-atoms/description/ 题目: Given a chemical formula (giv ...

  7. WPF自定义控件之图形解锁控件 ScreenUnLock

    ScreenUnLock 与智能手机上的图案解锁功能一样.通过绘制图形达到解锁或记忆图形的目的. 本人突发奇想,把手机上的图形解锁功能移植到WPF中.也应用到了公司的项目中. 在创建ScreenUnL ...

  8. grpc rust 项目基本使用

    1. 安装依赖(rust 基本依赖就不说了,需要配置环境变量) protoc 参考: https://github.com/google/protobuf/releases/tag/v3.5.1 2. ...

  9. nginx 缓存处理

    核心指令   proxy_cache_path /data/nginx/cache/one levels=1:2 keys_zone=one:10m max_size=10g; proxy_cache ...

  10. Google Chrome 总提示flash插件过期,用命令行模式解决

    目标那改成:"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --args --allow-outdate ...