JAVA | Easiest solution using array | Explained ✅
Please Upvote :D\n---\nWe can have as many as 10^6 keys, so we initialise a boolean array of size 10^6 + 1 (0 based indexing).\n\n#### Calling add():\nWe put tr
# Please Upvote :D\n---\nWe can have as many as `10^6` keys, so we initialise a boolean array of size `10^6 + 1` (0 based indexing).\n\n#### *Calling `add()`:*\nWe put `true` at index `key` which means `key` is present in set.\n\n#### *Calling `remove()`:*\nWe put `false` at index `key` which means `key` is no more present in set.\n\n#### *Calling `contains()`:*\nWe will return `arr[key]` which will either be `true` or `false`.\n- `true` means set *contains* the specified key.\n- `false` means set *does not contain* the specified key.\n``` java []\nclass MyHashSet {\n    boolean[] setArray;\n    public MyHashSet() {\n        setArray = new boolean[1000000 + 1];\n    }\n\n    public void add(int key) {\n        setArray[key] = true;\n    }\n\n    public void remove(int key) {\n        setArray[key] = false;\n    }\n\n    public boolean contains(int key) {\n        return setArray[key];\n    }\n}\n\n// TC: O(1)\n// SC: O(10^6 + 1) => O(1)\n```
['Array', 'Java']