CPP | Faster than 90% | Easy
Since we do not need same elements multiple times, I used boolean array that can easily return the presence of the element in the array.\n\nAs per the constrain
Since we do not need same elements multiple times, I used boolean array that can easily return the presence of the element in the array.\n\nAs per the constraints the size of the array is 1000000 and all elements are initialised to false.\n\nLets take following test case :-\n\t\n\tMyHashSet hashSet = new MyHashSet();\n\thashSet.add(1);         \n\thashSet.add(2);         \n\thashSet.contains(1);\n\thashSet.contains(3);\n\thashSet.remove(2);\n\t\n\t1. Initialise the hashset.\n\t2. hashset.add(1);  --> arr[1] = true;\n\t3. hashset.add(2);  --> arr[2] = true;\n\t4. hashset.contains(1) --> arr[1] = true;\n\t5. hashset.contains(3) --> arr[3] = false;\n\t6. hashset.remove(2) --> arr[2]= false\n\n\n```\nclass MyHashSet {\npublic:\n    bool arr[1000000] {false};\n    MyHashSet() {\n    }\n    \n    void add(int key) {\n        arr[key] = true;\n    }\n    \n    void remove(int key) {\n        arr[key] = false;\n    }\n    bool contains(int key) {\n        return arr[key];\n    }\n};\n```
['C', 'C++']