Leetcode PHP题解--D75 706. Design HashMap

栏目: PHP · 发布时间: 5年前

内容简介:自行设计一个hashmap。需要实现题目内指定的函数。

D75 706. Design HashMap

题目链接

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》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

现代编译原理

现代编译原理

(美)安佩尔 / 赵克佳、黄春、沈志宇 / 人民邮电出版社 / 2006-4 / 45.00元

《现代编译原理:C语言描述》全面讲述了现代编译器的结构、编译算法和实现方法,是Andrew w.Apple的“虎书”——Modern Compiler Implementation——“红、蓝、绿”三序列之一。这三本书的内容基本相同。但是使用不同的语言来实现书中给出的一个编译器。本书使用的是更适合广大读者的c语言,而另外两本书分别采用ML语言和Java语言。本书的另一个特点是增加了一些其他编译原理......一起来看看 《现代编译原理》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

html转js在线工具
html转js在线工具

html转js在线工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具