705. Design HashSet
Description
Design a HashSet without using any built-in hash table libraries.
Implement MyHashSet
class:
void add(key)
Inserts the valuekey
into the HashSet.bool contains(key)
Returns whether the valuekey
exists in the HashSet or not.void remove(key)
Removes the valuekey
in the HashSet. Ifkey
does not exist in the HashSet, do nothing.
Example 1:
1 | Input |
Constraints:
0 <= key <= 10^6
- At most
10^4
calls will be made toadd
,remove
, andcontains
.
Hints/Notes
- 2025/03/20 Q2
- hash
- Leetcode solution
Solution
Language: C++
1 | class MyHashSet { |