摘要:题目链接题目分析设计一个哈希类。需要有添加元素函数,判断元素存在的函数,移除元素函数。思路这真的没什么好说的了我把要存的值作为数组的键存储。最终代码若觉得本文章对你有用,欢迎用爱发电资助。
D87 705. Design HashSet 题目链接
705. Design HashSet
题目分析设计一个哈希类。
需要有add添加元素函数,contains判断元素存在的函数,remove移除元素函数。
思路这真的没什么好说的了…我把要存的值作为数组的键存储。
最终代码</>复制代码
class MyHashSet {
protected $values = [];
/**
* Initialize your data structure here.
*/
function __construct() {
}
/**
* @param Integer $key
* @return NULL
*/
function add($key) {
$this->values[$key] = true;
}
/**
* @param Integer $key
* @return NULL
*/
function remove($key) {
if(isset($this->values[$key])){
unset($this->values[$key]);
}
}
/**
* Returns true if this set contains the specified element
* @param Integer $key
* @return Boolean
*/
function contains($key) {
return isset($this->values[$key]);
}
}
/**
* Your MyHashSet object will be instantiated and called as such:
* $obj = MyHashSet();
* $obj->add($key);
* $obj->remove($key);
* $ret_3 = $obj->contains($key);
*/
若觉得本文章对你有用,欢迎用爱发电资助。
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/31737.html
Problem esign a HashSet without using any built-in hash table libraries. To be specific, your design should include these functions: add(value): Insert a value into the HashSet. contains(value) : Retu...
摘要:题目链接题目分析自行设计一个。需要实现题目内指定的函数。思路我觉得这个没什么好说的吧最终代码若觉得本文章对你有用,欢迎用爱发电资助。 D75 706. Design HashMap 题目链接 706. Design HashMap 题目分析 自行设计一个hashmap。 需要实现题目内指定的函数。 思路 我觉得这个没什么好说的吧… 最终代码
摘要:一流转换为数组集合陈杨将流转换为数组将流转换为数组将流转换为集合将流转换为集合解析 一、流 转换为数组、集合 package com.java.design.java8.Stream; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context...
摘要:题目链接题目分析题目给定一个字符串数组,每个字符串分两部分,以空格分割。第一部分为访问次数,第二部分为域名。要求按同样的格式,分别返回顶级域名二级域名三级域名的访问次数。最终代码若觉得本文章对你有用,欢迎用爱发电资助。 811. Subdomain Visit Count 题目链接 811. Subdomain Visit Count 题目分析 题目给定一个字符串数组,每个字符串分两部...
摘要:题目链接题目分析给定一个只含和的字符串,返回一个数组。这个数组满足以下条件当为时,。当遇到时,在数组的当前下标位置前插入当前下标。最终代码个人认为这题不是很好描述。有空会尝试描述清楚这个问题。 942. DI String Match 题目链接 942. DI String Match 题目分析 给定一个只含I和D的字符串S,返回一个数组。 这个数组满足以下条件: 当S[i]为I时...
阅读 2863·2021-11-19 11:30
阅读 3128·2021-11-15 11:39
阅读 1900·2021-08-03 14:03
阅读 2076·2019-08-30 14:18
阅读 2132·2019-08-30 11:16
阅读 2286·2019-08-29 17:23
阅读 2678·2019-08-28 18:06
阅读 2615·2019-08-26 12:22