C++ code using BFS | O(n)
\nclass FindElements {\n    unordered_map<int, int> m;\npublic:\n    FindElements(TreeNode* root) {\n        queue<TreeNode*> q;\n        root->val = 0;\n      
```\nclass FindElements {\n    unordered_map<int, int> m;\npublic:\n    FindElements(TreeNode* root) {\n        queue<TreeNode*> q;\n        root->val = 0;\n        q.push(root);\n        m[0]++;\n        while(!q.empty()){\n            auto temp = q.front();\n            q.pop();\n            m[temp->val]++;\n            if(temp->left){\n                temp->left->val = 2 * temp->val + 1;\n                q.push(temp->left);\n            }\n            if(temp->right){\n                temp->right->val = 2 * temp->val + 2;\n                q.push(temp->right);\n            }\n        }\n    }\n    \n    bool find(int target) {\n        if(m.find(target) != m.end())\n            return true;\n        return false;\n    }\n};\n```
[]