[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 ...
随机推荐
- Oracle使用expdp/impdp导出导入数据
这里假设已存在数据库用户,并是计划通过该用户导入导出该用户表空间上的数据.(我们这里假定用户名称为ls) 1.创建逻辑目录(数据库命令,sqlplus中执行) Oracle不能直接指定系统目录让他去读 ...
- 返回JSON格式(二十五)
在上述例子中,通过@ControllerAdvice统一定义不同Exception映射到不同错误处理页面.而当我们要实现RESTful API时,返回的错误是JSON格式的数据,而不是HTML页面,这 ...
- 转: Linux mount/unmount命令
https://blog.csdn.net/okhymok/article/details/76616892 楼主具体哪里转的 我不清楚 好像没看到原始出处 开机自动挂载 如果我们想实现开机自动挂载某 ...
- NumPy for MATLAB users
http://mathesaurus.sourceforge.net/matlab-numpy.html Help MATLAB/Octave Python Description dochelp - ...
- 蓝桥杯—BASIC-25 回形取数
题目:回形取数就是沿矩阵的边取数,若当前方向上无数可取或已经取过,则左转90度.一开始位于矩阵左上角,方向向下.输入格式 输入第一行是两个不超过200的正整数m, n,表示矩阵的行和列.接下来m行每行 ...
- C#通过shell32获取文件详细备注信息
1.从系统Window/System32文件夹中Copy出 Shell32.dll Com组件 将Shell32.dll文件引用到项目中,并设置“嵌入互操作类型”为false http://blog. ...
- 四:(之四)基于已有镜像构建自己的Docker镜像
4构建自己的Docker镜像 4.1常用命令: 等同于docker commit 将一个被改变的容器创建成一个新的image 等同于docker build 通过Dockerfile创建一个image ...
- 【转载二】Grafana系列教程–Grafana的下载及安装
本篇教程,waitig 来为大家介绍一下Grafana的安装及运行的方式. 更多Grafana技术请加入<InfluxDB&Grafana技术交流群:580487672(点击加入)> ...
- Linux3.10.0块IO子系统流程(1)-- 上层提交请求
Linux通用块层提供给上层的接口函数是submit_bio.上层在构造好bio之后,调用submit_bio提交给通用块层处理. submit_bio函数如下: void submit_bi ...
- CodeForces - 779D
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But i ...