C++/Java hash set, O(1)
Iterative approch to resolve tree values and populate hash map.\n\nC++\nCPP\nunordered_set<int> s;\nFindElements(TreeNode* root) {\n    queue<pair<TreeNode*, in
Iterative approch to resolve tree values and populate hash map.\n\n**C++**\n```CPP\nunordered_set<int> s;\nFindElements(TreeNode* root) {\n    queue<pair<TreeNode*, int>> q;\n    q.push({root, 0});\n    while (!q.empty()) {\n        auto p = q.front(); q.pop();\n        if (p.first != nullptr) {\n            s.insert(p.second);\n            q.push({p.first->left, p.second * 2 + 1});\n            q.push({p.first->right, p.second * 2 + 2});\n        }\n    }\n}\nbool find(int target) {\n    return s.find(target) != end(s);\n}\n```\n**Java**\n```Java\nSet<Integer> s = new HashSet<>(); \npublic FindElements(TreeNode root) {\n    Queue<TreeNode> q = new LinkedList<>();\n    root.val = 0;\n    q.add(root);\n    while(q.size() > 0) {\n        TreeNode r = q.poll();\n        s.add(r.val);\n        if (r.left != null) {\n            r.left.val = r.val * 2 + 1;\n            q.add(r.left);\n        }\n        if (r.right != null) { \n            r.right.val = r.val * 2 + 2;\n            q.add(r.right);\n        }            \n    }\n}\npublic boolean find(int target) {\n    return s.contains(target);\n}\n```\n#### Complexity Analysis\n- Time: \n\t- `O(n)` to populate tree values into the hash map.\n\t- `O(1)` to check the hash map.\n- Memory: `O(n)`.
[]