Given a binary tree with the following rules: root.val == 0 If treeNode.val == x and treeNode.left != null, then treeNod

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Given a binary tree with the following rules: root.val == 0 If treeNode.val == x and treeNode.left != null, then treeNod

Post by answerhappygod »

Given a binary tree with the following rules: root.val == 0 If
treeNode.val == x and treeNode.left != null, then treeNode.left.val
== 2 * x + 1 If treeNode.val == x and treeNode.right != null, then
treeNode.right.val == 2 * x + 2 Now the binary tree is
contaminated, which means all treeNode.val have been changed to -1.
Implement the FindElements class: FindElements(TreeNode* root)
Initializes the object with a contaminated binary tree and recovers
it. bool find(int target) Returns true if the target value exists
in the recovered binary tree. /** * 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:
FindElements(TreeNode* root) { } bool find(int target) { } }; /** *
Your FindElements object will be instantiated and called as such: *
FindElements* obj = new FindElements(root); * bool param_1 =
obj->find(target);
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply