Day 21 Daily LeetCode challenge problem || [JAVA ]|| O(1)
Approach 1 :\n\nIn Order to archive \n   * add   - O(1)   \n   * remove   - O(1)\n   * contains  - O(1)\n\nwith the compromising O(10^6) space.\n\nwe take an Ar
Approach 1 :\n\nIn Order to archive \n   * add   - O(1)   \n   * remove   - O(1)\n   * contains  - O(1)\n\nwith the compromising O(10^6) space.\n\nwe take an Array of size 10^6+1, Initialize array for all the elements from 0 to 10^6 and keep a check whether a certain key is present or not by looking at its value.\n * Contains\n if value == 0 element not present;\n if value is greater than 0 element is present;\n \n * add \n  increment the value of of given key\'s index\n  \n  * remove\n  assign the value zero to given key\'s index\n  \n  \n```\nclass MyHashSet {\n\n    int[] arr;\n    \n    public MyHashSet() {\n     arr=new int[1000001];    \n    }\n    \n    public void add(int key) {   \n        arr[key]=1;    //O(1)\n    }\n    \n    public void remove(int key) {\n        arr[key]=0;    //O(1)\n    }\n    \n    public boolean contains(int key) {\n        //O(1)\n        if(arr[key]==0) return false;\n        else return true;\n    }\n}\n```\n
['Array', 'Java']