No cheating || C++ || Easy to understand
If u use array or map, that\'s easy and space is always O(n), but it\'s not like a hash set.\nIdea in hash set, use the bucket, for each bucket contains keys =>
If u use array or map, that\'s easy and space is always O(n), but it\'s not like a hash set.\nIdea in hash set, use the bucket, for each bucket contains keys => Time and space is balance.\nSpace is the number of element in every bucket.\nTime in add, remove, contains in the worst case is O(10^6 / the number of bucket)\n\n\t//Solution 1:\n    class MyHashSet {\n    public:\n        const int BUCKET_SIZE = 100; // whatever number u like\n        vector<int> bucket[100];\n        MyHashSet() {\n        \n        }\n    \n        void add(int key) { \n            int index = key % BUCKET_SIZE;\n            if(!contains(key))\n                bucket[index].push_back(key);\n        }\n    \n        void remove(int key) {\n            int index = key % BUCKET_SIZE;\n            for(int i = 0; i < bucket[index].size(); i++)\n                if(bucket[index][i] == key) { \n                    bucket[index].erase(bucket[index].begin() + i); \n                    break; \n                }\n        }\n    \n        bool contains(int key) {\n            int index = key % BUCKET_SIZE;\n            for(int i = 0; i < bucket[index].size(); i++)\n                if(bucket[index][i] == key) return true; \n            return false;\n        }\n    };\n    //Time fater than ~90%\n    //Space less than ~90%\n\t\n\t//Solution 2:\n\tclass MyHashSet {\n\tpublic:\n\t\tconst int BUCKET_SIZE = 123; // whatever number u like\n\t\tvector<int> bucket[123];\n\t\tMyHashSet() {\n\t\t\n\t\t}\n\n\t\tvoid add(int key) { \n\t\t\tint index = key % BUCKET_SIZE;\n\t\t\tif(!contains(key))\n\t\t\t\tbucket[index].push_back(key);\n\t\t}\n\n\t\tvoid remove(int key) {\n\t\t\tint index = key % BUCKET_SIZE;\n\t\t\tfor(vector<int>::iterator it = bucket[index].begin(); it != bucket[index].end(); it++)\n\t\t\t\tif(*it == key) { \n\t\t\t\t\tbucket[index].erase(it);\n\t\t\t\t\tbreak; \n\t\t\t\t}\n\t\t}\n\n\t\tbool contains(int key) {\n\t\t\tint index = key % BUCKET_SIZE;\n\t\t\tfor(vector<int>::iterator it = bucket[index].begin(); it != bucket[index].end(); it++)\n\t\t\t\tif(*it == key)  return true; \n\t\t\treturn false;\n\t\t}\n\t};\n\t//Time fater than ~90%\n\t//Space less than ~90%\n\t//https://leetcode.com/submissions/detail/684459562/\n\t
['C']