🌳57. 2 Solutions || Recursive [ DFS ] || Magic 🪄 || Short & Sweet Code !! || C++ Code Reference !!
\n# Code\ncpp [Using Set ]\n\nclass FindElements {\n\n    unordered_set<int>s;\npublic:\n    FindElements(TreeNode* a) { Traverse(a,0); }\n    \n    bool find(i
\n# Code\n```cpp [Using Set ]\n\nclass FindElements {\n\n    unordered_set<int>s;\npublic:\n    FindElements(TreeNode* a) { Traverse(a,0); }\n    \n    bool find(int T) { return s.count(T)>0;}\n\nprivate: \n    void Traverse(TreeNode* a,int x)\n    {\n        if(!a) return;\n\n        a->val=x;\n        s.insert(x);\n        Traverse(a->left,2*x+1);\n        Traverse(a->right,2*x+2);\n    }\n};\n\n\n```\n```cpp [No Extra Space ]\n\nclass FindElements {\n\n    TreeNode* Root=nullptr;\npublic:\n    FindElements(TreeNode* a):Root(a) {}\n    \n    bool find(int T) { return Find(Root,0,T); }\n\nprivate:\n\n    bool Find(TreeNode* a,int x,int T)\n    {\n        if(!a) return 0;\n        a->val=x;\n\n        if(a->val==T)return 1;\n        return (Find(a->left,2*x+1,T) || Find(a->right,2*x+2,T));\n    }\n};\n\n\n```\n\n\n---\n# *Guy\'s Upvote Pleasee !!* \n![up-arrow_68804.png](https://assets.leetcode.com/users/images/05f74320-5e1a-43a6-b5cd-6395092d56c8_1719302919.2666397.png)\n\n# ***(\u02E3\u203F\u02E3 \u035C)***\n\n\n
['Hash Table', 'Tree', 'Depth-First Search', 'Breadth-First Search', 'Design', 'Recursion', 'Binary Tree', 'C++']