Set
Implement a set data structure with the following methods:
CustomSet()
constructs a new instance of a setadd(int val)
addsval
to the setexists(int val)
returns whetherval
exists in the setremove(int val)
removes theval
in the set
This should be implemented without using built-in set.
Constraints
n ≤ 100,000
wheren
is the number of calls toadd
,exists
andremove
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