Skip to content

Commit b22c4c0

Browse files
authored
Create 0705-design-hashset.js
Solved design-hashset File(s) Added: 0705-design-hashset.js Language(s) Used: JavaScript Submission URL: https://leetcode.com/problems/design-hashset/submissions/647414890/
1 parent a59cf38 commit b22c4c0

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

javascript/0705-design-hashset.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
//https://leetcode.com/problems/design-hashset
3+
var MyHashSet = function() {
4+
this.set = [];
5+
};
6+
7+
/**
8+
* Time O(1) | Space O(1)
9+
* @param {number} key
10+
* @return {void}
11+
*/
12+
MyHashSet.prototype.add = function(key) {
13+
this.set[key] = key;
14+
};
15+
16+
/**
17+
* Time O(1) | Space O(1)
18+
* @param {number} key
19+
* @return {void}
20+
*/
21+
MyHashSet.prototype.remove = function(key) {
22+
this.set[key] = undefined;
23+
};
24+
25+
/**
26+
* Time O(1) | Space O(1)
27+
* @param {number} key
28+
* @return {boolean}
29+
*/
30+
MyHashSet.prototype.contains = function(key) {
31+
return this.set[key] !== undefined;
32+
};
33+
34+
/**
35+
* Your MyHashSet object will be instantiated and called as such:
36+
* var obj = new MyHashSet()
37+
* obj.add(key)
38+
* obj.remove(key)
39+
* var param_3 = obj.contains(key)
40+
*/

0 commit comments

Comments
 (0)