Skip to content

Commit 9e99e3e

Browse files
authored
Update 0705-design-hashset.js
made the code class based.
1 parent b22c4c0 commit 9e99e3e

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

javascript/0705-design-hashset.js

+30-29
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
1+
// https://leetcode.com/problems/design-hashset
2+
class MyHashSet {
3+
constructor() {
4+
this.set = [];
5+
}
16

2-
//https://leetcode.com/problems/design-hashset
3-
var MyHashSet = function() {
4-
this.set = [];
5-
};
7+
/**
8+
* Time O(1) | Space O(1)
9+
* @param {number} key
10+
* @return {void}
11+
*/
12+
add(key) {
13+
this.set[key] = key;
14+
}
615

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-
};
16+
/**
17+
* Time O(1) | Space O(1)
18+
* @param {number} key
19+
* @return {void}
20+
*/
21+
remove(key) {
22+
this.set[key] = undefined;
23+
}
1524

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-
};
25+
/**
26+
* Time O(1) | Space O(1)
27+
* @param {number} key
28+
* @return {boolean}
29+
*/
30+
contains(key) {
31+
return this.set[key] !== undefined;
32+
}
33+
}
3334

3435
/**
3536
* Your MyHashSet object will be instantiated and called as such:

0 commit comments

Comments
 (0)