Question
Given a binary tree and an integer targetSum, return true if the tree has a root - to - leaf path such that adding up
Given a binary tree and an integer targetSum, return true if the tree has a roottoleaf path such that adding up all the values along the path equals targetSum.
Example :
targetSum
Output: true
Explanation: The roottoleaf path with the target sum is shown.
Example: targetSum
Output: false Explanation: There is no roottoleaf path with sum
Input
The first line contains a single integer n indicates the length of array inorder inorder and postorder have the same length
The second line contains n integers in in inn separated by spaces, which indicate the the inorder traversal of the binary tree.
The third line containsnintegers post post postn separated by spaces, which indicate the the postorder traversal of the binary tree.
Output Print true if the tree has a roottoleaf path such that adding up all the values along the path equals targetSum.
Sample Input
Sample Output
true
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get StartedRecommended Textbook for
Precalculus
Authors: Michael Sullivan
9th edition
321716835, 321716833, 978-0321716835
Students also viewed these Programming questions
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
View Answer in SolutionInn App