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 ...
随机推荐
- js生成guid(唯一标识码)
在使用postman对接口进行测试的时候,有时候接口日志会要求写入随机标识码,这里我们可以使用js来生成. // Generate four random hex digits. function S ...
- HDU2473 Junk-Mail Filter 【可删除的并查集】
HDU2473 Junk-Mail Filter Problem Description Recognizing junk mails is a tough task. The method used ...
- web.xml中配置classpath:和classpath*:的区别和意思
首先 classpath是指 WEB-INF文件夹下的classes目录 解释classes含义: 1.存放各种资源配置文件 eg.init.properties log4j.properties s ...
- maven搭建多模块企业级项目
首先,前面几次学习已经学会了安装maven,如何创建maven项目等,最近的学习,终于有点进展了,搭建一下企业级多模块项目. 好了,废话不多说,具体如下: 首先新建一个maven项目,pom.xml的 ...
- matplotlib ----- 多子图, subplots
这一篇讲的比较详细. http://matplotlib.org/examples/pylab_examples/subplots_demo.html 官方文档给出的subplots用法, http: ...
- ballerina 学习三 根据swagger 以及protobuf 生成code
备注: 基本环境安装就不用介绍了,swagger 以及grpc 同时也不用介绍了,都是比较简单的代码,就是一个简单的测试 1. 初始化项目 ballerina init 项目结构如下: ├── R ...
- 模态对话框中的window.close关闭时会打开新页面
在模态对话框的页面的<head></head>加上<base target="_self"> 就不会打开新页面了.
- FileStream读写文件
读文件示例 try { // 打开文件 FileStream fs = new FileStream("D:\\not.txt", FileMode.Open, FileAcces ...
- 中兴G718C开发者模式开启
系统设置--关于手机--版本号,连按七次,打开开发者选项 请进入设置——连接到PC——默认连接类型——安装驱动,选择即可.然后将手机和电脑连接,打开“我的电脑”或“计算机”会弹出可移动盘符“USB D ...
- Zookeeper--集群管理
Zookeeper--集群管理 在多台服务器组成的集群中,需要监控每台服务器的状态,一旦某台服务器挂掉了或有新的机器加入集群,集群都要感知到,从而采取相应的措施.一个主动的集群可以自动感知节点的死亡和 ...