705. Design HashSet
Practice Design HashSet for free on NudgeCode: Easy, Array & Hash Table pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Build a set of integers without using a built-in set or hash table.
add(key)insertskey(adding it twice keeps one copy).remove(key)deleteskeyif it is present.contains(key)returns whetherkeyis in the set.
Each test is a list of operations and their arguments; the expected output lists what each call returns (null for calls that return nothing).
Example
["MyHashSet","add","add","contains","contains","add","contains","remove","contains"]
[[],[1],[2],[1],[3],[2],[2],[2],[2]]
-> [null,null,null,true,false,null,true,null,false]
Constraints
- 0 <= key <= 10^6
- Up to 10^4 calls in total