leetcode706
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的更多相关文章
- [Swift]LeetCode706. 设计哈希映射 | Design HashMap
Design a HashMap without using any built-in hash table libraries. To be specific, your design should ...
- LeetCode706. Design HashMap
题目 不使用任何内建的哈希表库设计一个哈希映射 具体地说,你的设计应该包含以下的功能 put(key, value):向哈希映射中插入(键,值)的数值对.如果键对应的值已经存在,更新这个值. get ...
- Leetcode706.Design HashMap设计哈希映射
不使用任何内建的哈希表库设计一个哈希映射 具体地说,你的设计应该包含以下的功能 put(key, value):向哈希映射中插入(键,值)的数值对.如果键对应的值已经存在,更新这个值. get(key ...
随机推荐
- win8 ie10 debug flex
win8 ie10 使用flash debug方法: 删除c:\WINDOWS\system32\Macromed\Flash.c:\WINDOWS\SysWOW64\Macromed\Flash里面 ...
- C++头文件预编译与命名空间使用方法
宏指令的预编译用法,用于多文件的头文件预编译判断 头文件代码: #include <iostream> #ifndef XB_H//预编译判断XB_H代码段是否被执行 #define XB ...
- CodeForces - 258D:Little Elephant and Broken Sorting(概率DP)
题意:长度为n的排列,m次交换xi, yi,每个交换x,y有50%的概率不发生,问逆序数的期望 .n, m <= 1000 思路:我们只用维护大小关系,dp[i][j]表示位置i的数比位置j的 ...
- div横排放置对齐问题;block,inline,inline-block区别
1.左右两个div都设置为float:left,如果右边div没有设置宽度,右边div的宽度会根据div里的内容自动调整. 缺点:不易控制 2.只有左侧div设置为float:left,右侧div设置 ...
- 《DSP using MATLAB》示例9.2
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
- python第三方库
autopy autopy是一个自动化操作的python库,可以模拟一些鼠标.键盘事件,还能对屏幕进行访问 pywin32 win32api的python封装 PIL python的图形图像处理框架
- java 并发时使用条件变量--Condition
lock--unlock的方式在实际中使用较少,一般使用synchronized获取对象的内部锁替代,但是lock--unlock对了解synchronized有很大的帮助. 创建一个bank对象用于 ...
- Let’s Encrypt 将于 2018 年免费提供通配符证书
旨在让每个网站都启用 HTTPS 加密的 Let's Encrypt CA 宣布将于 2018 年 1 月免费提供通配符证书(Wildcard certificate).通配符证书是一种可被多个子域使 ...
- 虚拟路由冗余协议VRRP
一.VRRP简介 虚拟路由冗余协议VRRP(Virtual Router Redundancy Protocol)通过把几台路由设备联合组成一台虚拟的路由设备,将虚拟路由设备的IP地址作为用户的默认网 ...
- vim初探
https://github.com/spf13/spf13-vim 安装了此博主的开源项目. :vsp ——竖分屏 :sp ——横分屏