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题 写在开头:我作为一个老实人,一向非常反感骗赞.收智商税两种行为.前几天看到不止两三位用户说自己辛苦写了干货,结果收藏数是点赞数的三倍有余,感觉自己的 ...
随机推荐
- Hadoop(十一):组合任务概述和格式
组合任务概述 一些复杂的任务很难由一个MR处理完成,所以一般需要将其拆分成为多个简单的MR子任务来执行. MapReduce框架中对于这类的问题提供了几种方式进行任务执行流程的控制,主要包括以下几种方 ...
- java中的动手动脑
1.关于构造函数的问题 为什么上面的代码不能通过编译? 因为当你没有定义构造函数时,java编译器在编译时会自动生成一个无参的构造函数,上面的代码就可以进行执行了.但是当你顶一个构造函数时,编译器将不 ...
- html的嵌套规则
html元素分为块状元素和内联元素,块状元素作为其他元素的容器. 块状元素可以嵌套其他块状元素 块状元素可以嵌套内联元素 内联元素不能嵌套块状元素 p内不能嵌套块状元素 有几个特殊块状元素只能包含内联 ...
- 2017蓝桥杯承压计算(C++ B组)
标题:承压计算X星球的高科技实验室中整齐地堆放着某批珍贵金属原料.每块金属原料的外形.尺寸完全一致,但重量不同.金属材料被严格地堆放成金字塔形. ...
- C语言 文件操作(五)
(1)size_t fread ( void * ptr, size_t size, size_t count, FILE * stream ); 其中,ptr:指向保存结果的指针:size:每个数据 ...
- ArrayList、LinkedList和Vector源码分析
ArrayList.LinkedList和Vector源码分析 ArrayList ArrayList是一个底层使用数组来存储对象,但不是线程安全的集合类 ArrayList的类结构关系 public ...
- "文本加粗"组件:<b> —— 快应用组件库H-UI
 <import name="b" src="../Common/ui/h-ui/text/c_tag_b"></import> &l ...
- 《深入理解 Java 虚拟机》读书笔记:垃圾收集器与内存分配策略
正文 垃圾收集器关注的是 Java 堆和方法区,因为这部分内存的分配和回收是动态的.只有在程序处于运行期间时才能知道会创建哪些对象,也才能知道需要多少内存. 虚拟机栈和本地方法栈则不需要过多考虑回收的 ...
- Redis之事务操作
1.Redis事务的概念: Redis 事务的本质是一组命令的集合.事务支持一次执行多个命令,一个事务中所有命令都会被序列化.在事务执行过程,会按照顺序串行化执行队列中的命令,其他客户端提交的命令请求 ...
- Salesforce 学习 | 官方总结最实用的Spring '20新功能
在Spring '20正式发布之前,Trailblazers 社区举行了一个名为Treasure Hunt的在线活动,通过预览沙盒,分享他们认为Spring ‘20中最重要的功能.这篇文章就来盘点一下 ...
