File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 134
134
700|[ Search in a Binary Search Tree] ( ./0700-search-in-a-binary-search-tree.js ) |Easy|
135
135
701|[ Insert into a Binary Search Tree] ( ./0701-insert-into-a-binary-search-tree.js ) |Medium|
136
136
704|[ Binary Search] ( ./0704-binary-search.js ) |Easy|
137
+ 705|[ Design HashSet] ( ./0705-design-hashset.js ) |Easy|
137
138
706|[ Design HashMap] ( ./0706-design-hashmap.js ) |Easy|
138
139
713|[ Subarray Product Less Than K] ( ./0713-subarray-product-less-than-k.js ) |Medium|
139
140
722|[ Remove Comments] ( ./0722-remove-comments.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 705. Design HashSet
3
+ * https://leetcode.com/problems/design-hashset/
4
+ * Difficulty: Easy
5
+ *
6
+ * Design a HashSet without using any built-in hash table libraries.
7
+ *
8
+ * Implement MyHashSet class:
9
+ * - void add(key) Inserts the value key into the HashSet.
10
+ * - bool contains(key) Returns whether the value key exists in the
11
+ * HashSet or not.
12
+ * - void remove(key) Removes the value key in the HashSet. If key
13
+ * does not exist in the HashSet, do nothing.
14
+ */
15
+
16
+ var MyHashSet = function ( ) {
17
+ this . _keys = [ ] ;
18
+ } ;
19
+
20
+ /**
21
+ * @param {number } key
22
+ * @return {void }
23
+ */
24
+ MyHashSet . prototype . add = function ( key ) {
25
+ this . _keys [ key ] = 1 ;
26
+ } ;
27
+
28
+ /**
29
+ * @param {number } key
30
+ * @return {void }
31
+ */
32
+ MyHashSet . prototype . remove = function ( key ) {
33
+ this . _keys [ key ] = undefined ;
34
+ } ;
35
+
36
+ /**
37
+ * @param {number } key
38
+ * @return {boolean }
39
+ */
40
+ MyHashSet . prototype . contains = function ( key ) {
41
+ return this . _keys [ key ] !== undefined ;
42
+ } ;
You can’t perform that action at this time.
0 commit comments