LeetCode 706. Design HashMap (设计哈希映射)
题目标签:HashMap
题目让我们设计一个 hashmap, 有put, get, remove 功能。
建立一个 int array, index 是key, 值是 value,具体看code。
Java Solution:
Runtime: 76 ms, faster than 27.53%
Memory Usage: 58.2 MB, less than 31.57%
完成日期:03/18/2019
关键点:int array
- class MyHashMap {
- int [] map;
- /** Initialize your data structure here. */
- public MyHashMap() {
- map = new int[1000001];
- Arrays.fill(map, -1);
- }
- /** value will always be non-negative. */
- public void put(int key, int value) {
- map[key] = value;
- }
- /** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */
- public int get(int key) {
- return map[key];
- }
- /** Removes the mapping of the specified value key if this map contains a mapping for the key */
- public void remove(int key) {
- map[key] = -1;
- }
- }
- /**
- * Your MyHashMap object will be instantiated and called as such:
- * MyHashMap obj = new MyHashMap();
- * obj.put(key,value);
- * int param_2 = obj.get(key);
- * obj.remove(key);
- */
参考资料:N/A
LeetCode 题目列表 - LeetCode Questions List
题目来源:https://leetcode.com/
LeetCode 706. Design HashMap (设计哈希映射)的更多相关文章
- Leetcode706.Design HashMap设计哈希映射
不使用任何内建的哈希表库设计一个哈希映射 具体地说,你的设计应该包含以下的功能 put(key, value):向哈希映射中插入(键,值)的数值对.如果键对应的值已经存在,更新这个值. get(key ...
- [leetcode] 706. Design HashMap
题目 Design a HashMap without using any built-in hash table libraries. Implement the MyHashMap class: ...
- LeetCode 706 Design HashMap 解题报告
题目要求 Design a HashMap without using any built-in hash table libraries. To be specific, your design s ...
- LeetCode 705. Design HashSet (设计哈希集合)
题目标签:HashMap 题目让我们设计一个 hashset,有add,contains,remove 功能. 建立一个boolean array,index 是数字的值,具体看code. Java ...
- 706. Design HashMap 实现哈希表
[抄题]: public MyHashMap() { 主函数里面是装非final变量的,如果没有,可以一个字都不写 } [暴力解法]: 时间分析: 空间分析: [优化后]: 时间分析: 空间分析: ...
- Java实现 LeetCode 706 设计哈希映射(数组+链表)
706. 设计哈希映射 不使用任何内建的哈希表库设计一个哈希映射 具体地说,你的设计应该包含以下的功能 put(key, value):向哈希映射中插入(键,值)的数值对.如果键对应的值已经存在,更新 ...
- Leetcode PHP题解--D75 706. Design HashMap
2019独角兽企业重金招聘Python工程师标准>>> D75 706. Design HashMap 题目链接 706. Design HashMap 题目分析 自行设计一个has ...
- 706. Design HashMap - LeetCode
Question 706. Design HashMap Solution 题目大意:构造一个hashmap 思路:讨个巧,只要求key是int,哈希函数选择f(x)=x,规定key最大为100000 ...
- 【Leetcode_easy】706. Design HashMap
problem 706. Design HashMap solution1: class MyHashMap { public: /** Initialize your data structure ...
随机推荐
- ubantu MongoDB安装
转 https://blog.csdn.net/flyfish111222/article/details/51886787 本博文介绍了MongoDB,并详细指引读者在Ubuntu下MongoDB的 ...
- NX自动出图
小秀一下战果: 1. 自动添加图框2. 自动添加投影视图3. 自动标注外形尺寸4. 根据工艺要求,自动添加公差5. 自动孔表6. 批量打印 欢迎大家积极吐槽哈 [视频演示] http://v.youk ...
- Linux基础之操作系统
一.什么是操作系统 简单来说,操作系统就是一个协调.管理和控制计算机硬件资源和软件资源的控制程序. 二.操作系统存在的意义 究根结底,我们日常对计算机的管理是对计算机硬件的管理.经过近百年的时间,现代 ...
- python3.x Day3 文件编码
文件编码: 知识点不多,但及其重要,python2和python3处理机制还有不同点,需要注意. 首先: 编码.数据类型,完全不同的概念. 文件编码:可以遵循开发环境.可以自行设定. 变量值编码:py ...
- Swoft 新手向教程 - 通过 Docker 搭建一个开发环境
本系列文章将从使用层面介绍 Swoft 框架的使用及业务开发,面向初中级的 PHPer Swoft首个基于 Swoole 原生协程的新时代 PHP 高性能协程全栈组件化框架,内置协程网络服务器及常用的 ...
- python爬虫22 | 以后我再讲python「模拟登录」我就是狗
接下来就是 学习python的正确姿势 做爬虫 绕不开模拟登录 为此小帅b给大家支了几招 python爬虫19 | 遇到需要的登录的网站怎么办?用这3招轻松搞定! 有些网站的登录很弱鸡 传个用户名和密 ...
- Django-前后台的数据交互
Django 从后台往前台传递数据时有多种方法可以实现. 最简单的后台是这样的: from django.shortcuts import render def main_page(request): ...
- 1.Ubuntu查看Python版本
1.输入命令:ls -l /usr/bin/python*
- BZOJ 2095 [POI2010]Bridges (最大流、欧拉回路)
洛谷上有这题,但是输出方案缺SPJ..(而且我也懒得输出方案了) 题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=2095 题解: 首先判 ...
- Netty学习总结(4)——图解Netty之Pipeline、channel、Context之间的数据流向
以下所绘制图形均基于Netty4.0.28版本. 一.connect(outbound类型事件) 当用户调用channel的connect时,会发起一个outbound类型的事件,该事件将在pipel ...