C++ Real Solution for Interviews O(1) Operations
\nclass MyHashSet {\n    struct Node {\n        int digit;\n        bool val;\n        vector<Node *> children;\n        \n        Node(int digit) {\n          
```\nclass MyHashSet {\n    struct Node {\n        int digit;\n        bool val;\n        vector<Node *> children;\n        \n        Node(int digit) {\n            this->val = false;\n            this->digit = digit;\n        }\n    };\n    \n    Node *root;\npublic:\n    MyHashSet() {\n        root = new Node(0);\n    }\n    \n    void add(int key) {\n        if(key == 0) {\n            root->val = true;\n            return;\n        }\n        \n        Node *cur = root;\n        \n        while(key) {\n            bool found = false;\n            \n            for(auto i:cur->children) {\n                if(i->digit == key%10) {\n                    found = true;\n                    cur = i;\n                    break;\n                }\n            }\n            \n            if(!found) {\n                cur->children.push_back(new Node(key%10));\n                cur = cur->children.back();\n            }\n            \n            key /= 10;\n        }\n        \n        cur->val = true;\n    }\n    \n    void remove(int key) {\n        if(key == 0) {\n            root->val = false;\n            return;\n        }\n        \n        Node *cur = root;\n        \n        while(key) {\n            bool found = false;\n            \n            for(auto i:cur->children) {\n                if(i->digit == key%10) {\n                    found = true;\n                    cur = i;\n                    break;\n                }\n            }\n            \n            if(!found)\n            return;\n            \n            key /= 10;\n        }\n        \n        cur->val = false;\n    }\n    \n    bool contains(int key) {\n        if(key == 0)\n        return root->val;\n        \n        Node *cur = root;\n        \n        while(key) {\n            bool found = false;\n            \n            for(auto i:cur->children) {\n                if(i->digit == key%10) {\n                    found = true;\n                    cur = i;\n                    break;\n                }\n            }\n            \n            if(!found) \n            return false;\n            \n            key /= 10;\n        }\n        \n        return cur->val;\n    }\n};\n```\n\nThe N-ary Tree looks like\n\n\t\t\t\t\t\t\t\t\t\t\t\t      0\n\t\t\t\t\t\t\t\t0    1    2    3    4    5    6    7    8    9\n\t\t\t\t\t\t\t   0-9  0-9  0-9  0-9  0-9  0-9  0-9  0-9  0-9  0-9\n\t\t\t\t\t\t\t   \nand so on, where 0-9 are digits.\nwe mark the val as true where we find the number.\n\nif we want to add 201,\nThen val of Node with digit 1 will be marked as true.\n\n```\n\t\t\t\t\t\t\t\t0 (Only for key = 0)\n\t\t\t\t\t\t\t   /\n\t\t\t\t\t\t     2\n\t\t\t\t\t\t       \\\n\t\t\t\t\t\t\t     0\n\t\t\t\t\t\t       /\n\t\t\t\t\t\t     1 (val = true)\n```\n\n**Note:** *Val of Node with digit 2 and 0 in the above tree will be false as they will be true when we add 2 and 20 respectively i.e. when a number is added only the Node with last digit is marked as true.*\n\n**Note 2:** *For demonstration I\'ve explained as 2 -> 0 -> 1 for 201 but in code its like 1 -> 0 -> 2 i.e. we are going in reverse order in while(key) loop.*\n\n
[]