内容简介:自行设计一个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);
*/
若觉得本文章对你有用,欢迎用 爱发电 资助。
以上所述就是小编给大家介绍的《Leetcode PHP题解--D75 706. Design HashMap》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
算法设计与分析基础
Anany Levitin / 潘彦 / 清华大学出版社 / 2015-2-1 / 69.00元
作者基于丰富的教学经验,开发了一套全新的算法分类方法。该分类法站在通用问题求解策略的高度,对现有大多数算法准确分类,从而引领读者沿着一条清晰、一致、连贯的思路来探索算法设计与分析这一迷人领域。《算法设计与分析基础(第3版)》作为第3版,相对前版调整了多个章节的内容和顺序,同时增加了一些算法,并扩展了算法的应用,使得具体算法和通用算法设计技术的对应更加清晰有序;各章累计增加了70道习题,其中包括一些......一起来看看 《算法设计与分析基础》 这本书的介绍吧!