forked from JoshCrozier/leetcode-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0705-design-hashset.js
42 lines (38 loc) · 910 Bytes
/
0705-design-hashset.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* 705. Design HashSet
* https://leetcode.com/problems/design-hashset/
* Difficulty: Easy
*
* Design a HashSet without using any built-in hash table libraries.
*
* Implement MyHashSet class:
* - void add(key) Inserts the value key into the HashSet.
* - bool contains(key) Returns whether the value key exists in the
* HashSet or not.
* - void remove(key) Removes the value key in the HashSet. If key
* does not exist in the HashSet, do nothing.
*/
var MyHashSet = function() {
this._keys = [];
};
/**
* @param {number} key
* @return {void}
*/
MyHashSet.prototype.add = function(key) {
this._keys[key] = 1;
};
/**
* @param {number} key
* @return {void}
*/
MyHashSet.prototype.remove = function(key) {
this._keys[key] = undefined;
};
/**
* @param {number} key
* @return {boolean}
*/
MyHashSet.prototype.contains = function(key) {
return this._keys[key] !== undefined;
};