File tree Expand file tree Collapse file tree 1 file changed +30
-29
lines changed Expand file tree Collapse file tree 1 file changed +30
-29
lines changed Original file line number Diff line number Diff line change 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:
You can’t perform that action at this time.
0 commit comments