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);
*/

若觉得本文章对你有用,欢迎用爱发电资助。

转载于:https://my.oschina.net/u/2246923/blog/3055860

Leetcode PHP题解--D75 706. Design HashMap的更多相关文章

  1. 706. Design HashMap - LeetCode

    Question 706. Design HashMap Solution 题目大意:构造一个hashmap 思路:讨个巧,只要求key是int,哈希函数选择f(x)=x,规定key最大为100000 ...

  2. 【Leetcode_easy】706. Design HashMap

    problem 706. Design HashMap solution1: class MyHashMap { public: /** Initialize your data structure ...

  3. [leetcode] 706. Design HashMap

    题目 Design a HashMap without using any built-in hash table libraries. Implement the MyHashMap class: ...

  4. 【LeetCode】706. Design HashMap 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  5. LeetCode 706 Design HashMap 解题报告

    题目要求 Design a HashMap without using any built-in hash table libraries. To be specific, your design s ...

  6. [LeetCode&Python] Problem 706. Design HashMap

    Design a HashMap without using any built-in hash table libraries. To be specific, your design should ...

  7. LeetCode 706. Design HashMap (设计哈希映射)

    题目标签:HashMap 题目让我们设计一个 hashmap, 有put, get, remove 功能. 建立一个 int array, index 是key, 值是 value,具体看code. ...

  8. 706. Design HashMap 实现哈希表

    [抄题]: public MyHashMap() {  主函数里面是装非final变量的,如果没有,可以一个字都不写 } [暴力解法]: 时间分析: 空间分析: [优化后]: 时间分析: 空间分析: ...

  9. Leetcode 简略题解 - 共567题

    Leetcode 简略题解 - 共567题     写在开头:我作为一个老实人,一向非常反感骗赞.收智商税两种行为.前几天看到不止两三位用户说自己辛苦写了干货,结果收藏数是点赞数的三倍有余,感觉自己的 ...

随机推荐

  1. python爬虫之requests的高级使用

    1.requests能上传文件 # 导入requests模块 import requests # 定义一个dict files = {'file': open('D:/360Downloads/1.t ...

  2. C#通用类库整理--日志记录

    日志的记录是将程序过程中的一些行为数据记录下来,方便开发.运维迅速的找到问题的所在,节省时间.使用时在 站点的web.config 中的<appSettings></appSetti ...

  3. BurpSuite 安装配置简明教程

    文章更新于:2020-04-14 按照惯例,需要的文件附上链接放在文首. 文件名:jdk-8u241-windows-x64.7z 文件大小:208.43 MB 下载链接:https://downlo ...

  4. VXLAN 基础教程:VXLAN 协议原理介绍

    VXLAN(Virtual eXtensible Local Area Network,虚拟可扩展局域网),是一种虚拟化隧道通信技术.它是一种 Overlay(覆盖网络)技术,通过三层的网络来搭建虚拟 ...

  5. ADB教程

    ADB教程 查看当前pc端连接多少设备 adb devices  adb连接android设备  adb connect  [192.168.3.113]  断开连接  adb disconnect  ...

  6. Tcl编程第四天,流程控制语句

    1. if {} { } elseif {} { } else { } 注意: 1.关键字 if elseif else 和大括号之间应该留有间距的.如果紧紧挨着会报错. 2.表条件的判断括号为大括号 ...

  7. 7.4 private 成员变量的私有

    /* * 学生类(age不能为负数.将age参数私有,创建方法判断age不为负.被private修饰的成员只能在本类中被访问,若想访问可以使用get.set方法) * * 通过对象直接访问成员变量,会 ...

  8. matplotlib locators

    2020-03-23 17:59:59 -- Edit by yangray The Locator class is the base class for all tick locators. Th ...

  9. 三、ARP协议和ICMP协议

    一.ARP协议 网络设备有数据要发送到另一台网络设备时,必须要知道对方的网络层地址(IP).IP地址由网络层来提供,但是仅有IP地址是不够的,IP数据报文必须封装成帧才能通过数据链路进行发送.数据帧必 ...

  10. rdd简单操作

    1.原始数据 Key value Transformations(example: ((1, 2), (3, 4), (3, 6)))  2. flatMap测试示例 object FlatMapTr ...