HashSet Implementation - Java - Boolean - Easy
Hi,\n\nThe implementation that I thought was to go for a boolean array with size 10^6 +2.\n\nAnd this is easy to add and remove the element in the boolean array
Hi,\n\nThe implementation that I thought was to go for a boolean array with size 10^6 +2.\n\nAnd this is easy to add and remove the element in the boolean array.\n\nJust return that boolean element to find whether it contains in set function.\n\nPlease upvote if this helps..\n\n```\n\tint size = (int)Math.pow(10, 6)+1;\n\tboolean[] flag;\n    public MyHashSet() {\n\t\tflag = new boolean[size];\n\t}\n    \n    public void add(int key) {\n        flag[key]=true;\n    }\n    \n    public void remove(int key) {\n        flag[key]=false;\n    }\n    \n    public boolean contains(int key) {\n        return flag[key];\n    }
['Java']