Leetcode PHP题解--D75 706. Design HashMap
D75 706. Design HashMap
题目链接
题目分析
自行设计一个hashmap。
需要实现题目内指定的函数。
思路
我觉得这个没什么好说的吧…
最终代码
<?php
class MyHashMap {
/**
* Initialize your data structure here.
*/
public $data = [];
function __construct() {
}
/**
* value will always be non-negative.
* @param Integer $key
* @param Integer $value
* @return NULL
*/
function put($key, $value) {
$this->data[$key] = $value;
}
/**
* Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key
* @param Integer $key
* @return Integer
*/
function get($key) {
return isset($this->data[$key])?$this->data[$key]:-1;
}
/**
* Removes the mapping of the specified value key if this map contains a mapping for the key
* @param Integer $key
* @return NULL
*/
function remove($key) {
unset($this->data[$key]);
}
}
/**
* Your MyHashMap object will be instantiated and called as such:
* $obj = MyHashMap();
* $obj->put($key, $value);
* $ret_2 = $obj->get($key);
* $obj->remove($key);
*/
若觉得本文章对你有用,欢迎用爱发电资助。
转载于:https://my.oschina.net/u/2246923/blog/3055860
Leetcode PHP题解--D75 706. Design HashMap的更多相关文章
- 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 ...
- [leetcode] 706. Design HashMap
题目 Design a HashMap without using any built-in hash table libraries. Implement the MyHashMap class: ...
- 【LeetCode】706. Design HashMap 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- LeetCode 706 Design HashMap 解题报告
题目要求 Design a HashMap without using any built-in hash table libraries. To be specific, your design s ...
- [LeetCode&Python] Problem 706. Design HashMap
Design a HashMap without using any built-in hash table libraries. To be specific, your design should ...
- LeetCode 706. Design HashMap (设计哈希映射)
题目标签:HashMap 题目让我们设计一个 hashmap, 有put, get, remove 功能. 建立一个 int array, index 是key, 值是 value,具体看code. ...
- 706. Design HashMap 实现哈希表
[抄题]: public MyHashMap() { 主函数里面是装非final变量的,如果没有,可以一个字都不写 } [暴力解法]: 时间分析: 空间分析: [优化后]: 时间分析: 空间分析: ...
- Leetcode 简略题解 - 共567题
Leetcode 简略题解 - 共567题 写在开头:我作为一个老实人,一向非常反感骗赞.收智商税两种行为.前几天看到不止两三位用户说自己辛苦写了干货,结果收藏数是点赞数的三倍有余,感觉自己的 ...
随机推荐
- .gitattributes
.gitattributes文件是一个文本文件,文件中的一行定义一个路径的若干属性.以行为单位设置一个路径下所有文件的属性,格式如下: 要匹配的文件模式 属性1 属性2 GRLF和LF CRLF,LF ...
- 1014 Waiting in Line (30 分)
Suppose a bank has N windows open for service. There is a yellow line in front of the windows which ...
- PTA数据结构与算法题目集(中文) 7-23
PTA数据结构与算法题目集(中文) 7-23 7-23 还原二叉树 (25 分) 给定一棵二叉树的先序遍历序列和中序遍历序列,要求计算该二叉树的高度. 输入格式: 输入首先给出正整数N(≤50) ...
- JavaScript中数组的两种排序方法详解(冒泡排序和选择排序)
一.冒泡排序的原理(从小到大) 相邻两个数进行比较,如果前一个数大于后一个数,那么就交换,否则不交换 原理剖析 比如有一组含有6个数字的数:5.3.7.2.1.6一共6个数字,做5次循环,每次循环相邻 ...
- BigDecimal 笔记
参数 BigDecimal 类主要有如下几个参数 这几个参数都比较好理解,看过这两个例子基本都能明白,现在总结一下就是 scale // 小数点后位数 precision // 一共位数 intCom ...
- 5个最佳WordPress通知栏插件
作者:品博客 链接:https://blog.pingbook.top/328/ 来源:品博客 著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. WordPress通知栏可有效地将 ...
- Mysql基础知识一
1.数据库的定义 数据:描述事物符号记录.(包括数字.文字.图形.图像.声音.档案记录等)以记录形式统一的格式进行存储. 广义上的数据:出现在计算机内部的一切二进制数据流都为数据 狭义上的数据:只是数 ...
- MySQL中information_schema 数据库 是干什么的
MySQL中information_schema是什么 大家在安装或使用MYSQL时,会发现除了自己安装的数据库以外,还有一个information_schema数据库. information_sc ...
- 2019-07-31【机器学习】无监督学习之降维NMF算法 (人脸特征提取)
代码 from numpy.random import RandomState #加载RandomState用于创建随机种子 import matplotlib.pyplot as plt from ...
- Daily Scrum 12/21/2015
Process: Zhaoyang: Integrate the oxford Speech API Code to the IOS client and do some UI optimizatio ...
