✅✅Beats 100%🔥C++🔥Python|| 🚀🚀Super Simple and Efficient Solution🚀🚀||🔥Python🔥C++✅✅
Complexity
Time complexity:O(n)

Space complexity:O(n)
Code
# Complexity
- Time complexity: $$O(n)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: $$O(n)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class FindElements {
 public:
  FindElements(TreeNode* root) {
    dfs(root, 0);
  }
  bool find(int target) {
    return vals.contains(target);
  }
 private:
  unordered_set<int> vals;
  void dfs(TreeNode* root, int val) {
    if (root == nullptr){
      return;
    }
    root->val = val;
    vals.insert(val);
    dfs(root->left, val * 2 + 1);
    dfs(root->right, val * 2 + 2);
  }
};
```
```python []
class FindElements:
  def __init__(self, root: TreeNode | None):
    self.vals = set()
    self.dfs(root, 0)
  def find(self, target: int) -> bool:
    return target in self.vals

  def dfs(self, root: TreeNode | None, val: int) -> None:
    if not root:
      return

    root.val = val
    self.vals.add(val)
    self.dfs(root.left, val * 2 + 1)
    self.dfs(root.right, val * 2 + 2)
```
['Hash Table', 'Tree', 'Depth-First Search', 'Breadth-First Search', 'Design', 'Binary Tree', 'C++', 'Python3']