Simple C++ Solution | Binary Tree | InOrder Traversal
SolutionComplexity

Time complexity:FindElements:O(n)find:O(1)


Space complexity:FindElements:O(n)find:O(1)

Code
# Solution
https://youtu.be/MzMYRFmV-PA

# Complexity
- Time complexity:
FindElements: $$O(n)$$
find: $$O(1)$$

- Space complexity:
FindElements: $$O(n)$$
find: $$O(1)$$

# Code
```cpp []
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class FindElements {
public:
    unordered_set<int> treeVals;
    void recoverTreeValues(TreeNode* root, int currVal){
        if(root==NULL) return;
        recoverTreeValues(root->left, currVal*2+1);
        treeVals.insert(currVal);
        recoverTreeValues(root->right, currVal*2+2);
    }
    FindElements(TreeNode* root) {
        recoverTreeValues(root, 0);
    }
    
    bool find(int target) {
        return treeVals.contains(target);
    }
};

/**
 * Your FindElements object will be instantiated and called as such:
 * FindElements* obj = new FindElements(root);
 * bool param_1 = obj->find(target);
 */
```
['C++']