[LeetCode&Python] Problem 705. Design HashSet
Design 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)
: Return whether the value exists in the HashSet or not.remove(value)
: Remove a value in the HashSet. If the value does not exist in the HashSet, do nothing.
Example:
MyHashSet hashSet = new MyHashSet();
hashSet.add(1);
hashSet.add(2);
hashSet.contains(1); // returns true
hashSet.contains(3); // returns false (not found)
hashSet.add(2);
hashSet.contains(2); // returns true
hashSet.remove(2);
hashSet.contains(2); // returns false (already removed)
Note:
- All values will be in the range of
[0, 1000000]
. - The number of operations will be in the range of
[1, 10000]
. - Please do not use the built-in HashSet library.
class MyHashSet(object): def __init__(self):
"""
Initialize your data structure here.
"""
self.hashSet=set() def add(self, key):
"""
:type key: int
:rtype: void
"""
self.hashSet.add(key) def remove(self, key):
"""
:type key: int
:rtype: void
"""
if key in self.hashSet:
self.hashSet.remove(key) def contains(self, key):
"""
Returns true if this set contains the specified element
:type key: int
:rtype: bool
"""
if key in self.hashSet:
return True
else:
return False # Your MyHashSet object will be instantiated and called as such:
# obj = MyHashSet()
# obj.add(key)
# obj.remove(key)
# param_3 = obj.contains(key)
[LeetCode&Python] Problem 705. Design HashSet的更多相关文章
- [LeetCode&Python] Problem 706. Design HashMap
Design a HashMap without using any built-in hash table libraries. To be specific, your design should ...
- 【Leetcode_easy】705. Design HashSet
problem 705. Design HashSet 题意: solution1: class MyHashSet { public: /** Initialize your data struct ...
- 【LeetCode】705. Design HashSet 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 位图法 数组法 日期 题目地址:https://le ...
- LeetCode 705 Design HashSet 解题报告
题目要求 Design a HashSet without using any built-in hash table libraries. To be specific, your design s ...
- LeetCode 705. Design HashSet (设计哈希集合)
题目标签:HashMap 题目让我们设计一个 hashset,有add,contains,remove 功能. 建立一个boolean array,index 是数字的值,具体看code. Java ...
- [LeetCode&Python] Problem 703. Kth Largest Element in a Stream
Design a class to find the kth largest element in a stream. Note that it is the kth largest element ...
- [LeetCode&Python] Problem 661. Image Smoother
Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother t ...
- [LeetCode&Python] Problem 108. Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. Fo ...
- [LeetCode&Python] Problem 492. Construct the Rectangle
For a web developer, it is very important to know how to design a web page's size. So, given a speci ...
随机推荐
- R语言中的采样与生成组合
不放回采样:sample(1:10, 5, replace = FALSE) 生成组合:
- docker图形化管理工具portainer
本章主要介绍docker的web图形化管理工具.这里使用 portainer(类似与dockui不过dockerui只支持单节点) 镜像名称 portainer/portainer 一.启动porta ...
- windows上dubbo-admin的安装
dubbo-admin的安装 (1)先下载好zookeeper包,因为启动dubbo-admin时需要先启动zookeeper zookeeper:dubbo的注册中心(自己下载 ,找到bin目录下的 ...
- 每天CSS学习之text-overflow
text-overflow是CSS3的一个属性,其作用是当文本溢出包含它的元素时,应该裁剪还是将多余的字符用省略号来表示. 该属性一般和overflow:hidden属性一起使用. text-over ...
- 图的关键路径,AOE,完整实现,C++描述
body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...
- 归并排序(Merging Sort)
body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...
- [Leetcode 101]判断对称树 Symmetric Tree
[题目] Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). ...
- 虚拟机中扩展linux系统存储空间
reference: https://blog.csdn.net/greenapple_shan/article/details/52799631 https://blog.csdn.net/lyd1 ...
- JavaScript作用域及作用域链详解、声明提升
相信大家在入门JavaScript这门语言时对作用域.作用域链.变量声明提升这些概念肯定会稀里糊涂,下面就来说说这几个 Javascript 作用域 在 Javascript 中,只有局部作用域和全局 ...
- docker从初识到深入
1:使用docker有哪些优势: 更快交付你的应用(Faster delivery of your applications) 让部署和测试更简单(Deploying and scaling more ...