[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 ...
随机推荐
- php 循环数组问题
$a = array('abe','ben','cam'); //foreach遍历数组时,实际上是遍历的数组的一个拷贝,并且在开始遍历之前会把指针指向拷贝的开始:,根据cow机制,写时,重新复制一份 ...
- Spring循环依赖
Spring-bean的循环依赖以及解决方式 Spring里面Bean的生命周期和循环依赖问题 什么是循环依赖? 循环依赖其实就是循环引用,也就是两个或者两个以上的bean互相持有对方,最终形成闭环. ...
- telnet的装配及xinetd的讨论
telnet由于是不安全的明文传输所以基本被ssh取代了,尤其是在Linux上:不过还是可能会用到,且启停方式还有些不同所以还是有必要说明一下. rpm -qa | grep telnet #查看是否 ...
- 转Generative Model 与 Discriminative Model
没有完全看懂,以后再看,特别是hmm,CRF那里,以及生成模型产生的数据是序列还是一个值,hmm应该是序列,和图像的关系是什么. [摘要] - 生成模型(Generative Model) :无 ...
- zabbix3.4.7实现企业微信告警,亲测可用!
Zabbix 新版微信告警 Zabbix可以通过多种方式把告警信息发送到指定人,常用的有邮件,短信报警方式,但是越来越多的企业开始使用zabbix结合微信作为主要的告警方式,这样可以及时有效的把告警信 ...
- Win10系列:VC++ Direct3D开发基础1
在介绍如何使用Direct3D项目模版来绘制立体图形之前,首先为读者介绍在Direct3D应用程序开发过程中涉及到的一些常用概念. (1)资源 资源是指可以被Direct3D图形管线所访问的内存空间, ...
- flask-admin fileadmin 上传文件,中文名的解决方案 重写部分secure_filename
class upload_view(FileAdmin): def _save_form_files(self, directory, path, form): super() filename = ...
- flask-admin有用的例子
flask-admin主页: https://github.com/flask-admin/flask-admin flask-admin克隆地址: https://github.com/flask- ...
- 四:(之一和之二) docker架构和底层技术分析(C/S架构)
1.架构和底层技术 Docker Host提供了RESTUL api,使docker client可以通过这些命令调用dockerd. Registry是一个公用的存储镜像的容器,类似于github. ...
- iPhoneX && iOS11 适配
最近实在是蛮闲的,这都得益于苹果爸爸给力的审核,已经半个月了(委屈) 这个问题已经很久了,但是还是希望分享给各位,当然网上的教程的确很多: 1.automaticallyAdjustsScrollVi ...