资讯专栏INFORMATION COLUMN

Leetcode PHP题解--D75 706. Design HashMap

sf190404 / 2493人阅读

摘要:题目链接题目分析自行设计一个。需要实现题目内指定的函数。思路我觉得这个没什么好说的吧最终代码若觉得本文章对你有用,欢迎用爱发电资助。

D75 706. Design HashMap 题目链接

706. Design HashMap

题目分析

自行设计一个hashmap。

需要实现题目内指定的函数。

思路

我觉得这个没什么好说的吧…

最终代码
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://www.ucloud.cn/yun/31613.html

相关文章

  • [LeetCode] 706. Design HashMap

    Problem Design a HashMap without using any built-in hash table libraries. To be specific, your design should include these functions: put(key, value) : Insert a (key, value) pair into the HashMap. If ...

    bergwhite 评论0 收藏0
  • Leetcode PHP题解--D87 705. Design HashSet

    摘要:题目链接题目分析设计一个哈希类。需要有添加元素函数,判断元素存在的函数,移除元素函数。思路这真的没什么好说的了我把要存的值作为数组的键存储。最终代码若觉得本文章对你有用,欢迎用爱发电资助。 D87 705. Design HashSet 题目链接 705. Design HashSet 题目分析 设计一个哈希类。 需要有add添加元素函数,contains判断元素存在的函数,remov...

    why_rookie 评论0 收藏0
  • Leetcode PHP题解--D36 811. Subdomain Visit Count

    摘要:题目链接题目分析题目给定一个字符串数组,每个字符串分两部分,以空格分割。第一部分为访问次数,第二部分为域名。要求按同样的格式,分别返回顶级域名二级域名三级域名的访问次数。最终代码若觉得本文章对你有用,欢迎用爱发电资助。 811. Subdomain Visit Count 题目链接 811. Subdomain Visit Count 题目分析 题目给定一个字符串数组,每个字符串分两部...

    inapt 评论0 收藏0
  • Leetcode PHP题解--D10 942. DI String Match

    摘要:题目链接题目分析给定一个只含和的字符串,返回一个数组。这个数组满足以下条件当为时,。当遇到时,在数组的当前下标位置前插入当前下标。最终代码个人认为这题不是很好描述。有空会尝试描述清楚这个问题。 942. DI String Match 题目链接 942. DI String Match 题目分析 给定一个只含I和D的字符串S,返回一个数组。 这个数组满足以下条件: 当S[i]为I时...

    yibinnn 评论0 收藏0
  • Leetcode PHP题解--D37 682. Baseball Game

    摘要:题目链接题目分析给定一个字符串数组,每一个字符串有以下形式数字。直接计算得分。。代表上一轮分数无效。思路这题没什么好说的了。用区分各种情况,进行相应处理即可。最终代码若觉得本文章对你有用,欢迎用爱发电资助。 682. Baseball Game 题目链接 682. Baseball Game 题目分析 给定一个字符串数组,每一个字符串有以下形式: 数字。直接计算得分。 +。代表本轮...

    wzyplus 评论0 收藏0

发表评论

0条评论

sf190404

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<