Set
Implement a set data structure with the following methods:
CustomSet()constructs a new instance of a setadd(int val)addsvalto the setexists(int val)returns whethervalexists in the setremove(int val)removes thevalin the set
This should be implemented without using built-in set.
Constraints
n ≤ 100,000wherenis the number of calls toadd,existsandremove
https://binarysearch.com/problems/Set
Examples
Example 1
Input
- methods =
['constructor', 'add', 'exists', 'remove', 'exists'] - arguments =
[[], [1], [1], [1], [1]]
Output
- answer =
[None, None, True, None, False]
Explanation
c = CustomSet()
c.add(1)
c.exists(1) == True
c.remove(1)
c.exists(1) == False
Leave a comment