-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.js
More file actions
40 lines (36 loc) · 798 Bytes
/
solution.js
File metadata and controls
40 lines (36 loc) · 798 Bytes
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
/**
* Initialize your data structure here.
*/
var MyHashSet = function() {
this.buckets = new Array(1000000)
this.buckets.fill(0)
};
/**
* @param {number} key
* @return {void}
*/
MyHashSet.prototype.add = function(key) {
this.buckets[key] = 1
};
/**
* @param {number} key
* @return {void}
*/
MyHashSet.prototype.remove = function(key) {
this.buckets[key] = 0
};
/**
* Returns true if this set did not already contain the specified element
* @param {number} key
* @return {boolean}
*/
MyHashSet.prototype.contains = function(key) {
return this.buckets[key] === 1
};
/**
* Your MyHashSet object will be instantiated and called as such:
* var obj = Object.create(MyHashSet).createNew()
* obj.add(key)
* obj.remove(key)
* var param_3 = obj.contains(key)
*/