Skip to content

Commit 2b34b1c

Browse files
committed
Add solution #705
1 parent c0ca330 commit 2b34b1c

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
700|[Search in a Binary Search Tree](./0700-search-in-a-binary-search-tree.js)|Easy|
135135
701|[Insert into a Binary Search Tree](./0701-insert-into-a-binary-search-tree.js)|Medium|
136136
704|[Binary Search](./0704-binary-search.js)|Easy|
137+
705|[Design HashSet](./0705-design-hashset.js)|Easy|
137138
706|[Design HashMap](./0706-design-hashmap.js)|Easy|
138139
713|[Subarray Product Less Than K](./0713-subarray-product-less-than-k.js)|Medium|
139140
722|[Remove Comments](./0722-remove-comments.js)|Medium|

solutions/0705-design-hashset.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
};

0 commit comments

Comments
 (0)