-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
39 lines (34 loc) · 787 Bytes
/
main.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
// URL: https://leetcode.com/problems/design-hashset/
var MyHashSet = function () {
this.set = {};
};
/**
* @param {number} key
* @return {void}
*/
MyHashSet.prototype.add = function (key) {
if (!this.contains(key))
this.set.push(key)
};
/**
* @param {number} key
* @return {void}
*/
MyHashSet.prototype.remove = function (key) {
if (this.contains(key))
this.set = this.set.filter(item => item !== key);
};
/**
* @param {number} key
* @return {boolean}
*/
MyHashSet.prototype.contains = function (key) {
return this.set.find(item => item === key) !== undefined;
};
/**
* Your MyHashSet object will be instantiated and called as such:
* var obj = new MyHashSet()
* obj.add(key)
* obj.remove(key)
* var param_3 = obj.contains(key)
*/