[C/C++ Solution] The find is O(1), uses a bitset instead of a set (saves memory)
If the tree is not too sparse, using a bitset uses less memory than an unordered_set. I think it amounts to only 8KiB, given the problem\'s upper node limit, en
If the tree is not too sparse, using a bitset uses less memory than an unordered_set. I think it amounts to only 8KiB, given the problem\'s upper node limit, enough to fit entirely in the CPU\'s cache. I also expect element access to compare favorably with an unordered_set\'s.\nIf lots of small trees are to be expected, preallocating a full-size bitset may be a pessimization, but replacing it with a (dynamic-sized) vector is fairly straightforward.\n\n```\nclass FindElements {\n    std::bitset< (2<<20) > vv;\n    \n    void recover(TreeNode* n, int ii) {\n        if(!n) { return; }\n        \n        vv[ii] = true;\n        recover(n->left, ii*2+1);\n        recover(n->right, ii*2+2);\n    }\npublic:\n    FindElements(TreeNode* root) {\n        recover(root, 0);\n    }\n    \n    bool find(int target) {\n        return vv[target] == true;\n    }\n};\n```
['C']