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. 【剑指offer】10矩阵覆盖

    原创博文,转载请注明出处! 0.简介 # 本文是牛客网<剑指offer>刷题笔记,笔记索引链接 1.题目 # 用2*1的小矩形横着或者竖着去覆盖更大的矩形.请问用n个2*1的小矩形无重叠地 ...

  2. 【test】

    {"type":[    {"name":"专题分类","num":1,"value":[      ...

  3. (转)spring AOP探索

    原文地址:http://www.cnblogs.com/zuoxiaolong/p/spring6.html 自己整理后,供自己学习方便: 目前由AOP联盟给出了AOP的标准,AOP联盟的规范只是提供 ...

  4. Scala的=>作用

    举例: var increase = (x: Int) => x + 1 increase(10) res0: Int = 11 类似于转化符号,=>指明这个函数把左边的东西(任何整数x) ...

  5. JavaScript 定时任务多事件冲突问题

    var iCount = setInterval(ChangeTime, 3500);//3.5秒请求一次函数 function ChangeTime() { $.ajax({ type: " ...

  6. Jquery 点击父类全选子类 , 子类选父类

    <p> <label style="font-size:18px;font-weight: bold;" class="checkboxs"& ...

  7. {Notes}{LaTeX}{enumerate}

    \usepackage{enumerate} \begin{enumerate}{(1)} \setcounter{enumi}{2} % begin with 2 \item first \item ...

  8. Spring Boot 入门之缓存和 NoSQL 篇(四)

    原文地址:Spring Boot 入门之缓存和 NoSQL 篇(四) 博客地址:http://www.extlight.com 一.前言 当系统的访问量增大时,相应的数据库的性能就逐渐下降.但是,大多 ...

  9. Ubuntu sudo: add-apt-repository: command not found

    安装缺少的指令即可 $ sudo apt-get install software-properties-common python-software-properties

  10. Android 从上层到底层-----app层

    CPU:RK3288 系统:Android 5.1 功能:上层 app 控制 led 亮灭 开发板:Firefly RK3288 MainActivity.java package com.aaron ...