[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 ...
随机推荐
- 连续三月涨势明显,PostgreSQL 将崛起?
33 分享 10 DB-Engines 是全球最流行的数据库排行榜之一,在近几个月的排行榜中,PostgreSQL 都保持着非常好的势头,从最稳(10月)到一路高涨(11月),再到稳步上升(12月 ...
- Django之cookie+session
前言 HTTP协议 是短连接.且状态的,所以在客户端向服务端发起请求后,服务端在响应头 加入cokie响应给浏览器,以此记录客户端状态: cook是来自服务端,保存在浏览器的键值对,主要应用于用户登录 ...
- Apache支持TRACE请求漏洞处理方案
trace和get一样是http的一种请求方法,该方法的作用是回显收到的客户端请求,一般用于测试服务器运行状态是否正常. 该方法结合浏览器漏洞可能造成跨站脚本攻击.修复方法如下: 编缉/etc/htt ...
- Oracle 如何将“26-9月 -17 06.46.00.000000000 下午”字符串转换成标准日期格式
今天,在读取日期格式数据时,出现这样的格式“26-9月 -17 06.46.00.000000000 下午”,在网上找了一下, 这个也是oracle的一种日期保存格式,数据都是日期类型,只是显示的结果 ...
- javascript 多个onclick function 取对应值
方法1: 直接获取值 <button onclick="aa(1)">执行</button> <button onclick="aa(2)& ...
- 【资料搜集】DirectX学习
[网站推荐:]GameRes游资网-游戏开发者门户 http://www.gameres.com/ [基础知识:] <游戏编程>第一部 基础篇 - GameRes.com http://d ...
- day28 黏包及黏包解决方案
今日主要内容: 一 .缓冲区 二.两种黏包现象 三.黏包现象的两种解决方案 四.打印进度条(补充的,了解即可) 1. 缓冲区 缓冲区的作用 : 将程序和网络解耦(这样做的好处是程序不会以为网速的快慢而 ...
- 图的拓扑排序,AOV,完整实现,C++描述
body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...
- sass 变量的声明 嵌套
sass 的默认变量一般是用来设置默认值,然后根据需求来覆盖的,覆盖的方式也很简单,只需要在默认变量之前重新声明下变量即可. $baseLineHeight: 2; $baseLineHeight: ...
- JavaWeb基础-Jsp基础语法
jsp基础语法 JSP的组成 静态内容.指令.表达式.小脚本.声明.注释 JSP的生命周期 用户发出index.jsp ,服务端判断是否是第一次请求,若是第一次请求,则tomcat中的JSP引擎中的文 ...