Problem
Design a HashSet without using any built-in hash table libraries.
Implement MyHashSet class:
void add(key)Inserts the valuekeyinto the HashSet.bool contains(key)Returns whether the valuekeyexists in the HashSet or not.void remove(key)Removes the valuekeyin the HashSet. Ifkeydoes not exist in the HashSet, do nothing.
Examples
Example 1:
| |
Constraints
0 <= key <= 10^6- At most
10^4calls will be made toadd,remove, andcontains.
Solution
Method 1 - Using Simple Array
Code
| |