LeetCode 705, Easy. Topics: Array, Hash Table, Linked List, Design, Hash Function. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 13 parametrized pytest cases, and a playground notebook:
Problem
Design a HashSet without using any built-in hash table libraries.
Implement the MyHashSet class:
void add(key) Inserts the value key into the HashSet.
bool contains(key) Returns whether the value key exists in the HashSet or not.
void remove(key) Removes the value key in the HashSet. If key does not exist in the HashSet, do nothing.
Examples
Constraints
- 0 <= key <= 10^6
- At most 10^4 calls will be made to
add, remove, and contains.
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
NeetCode 250, NeetCode All. Last modified on September 7, 2026