Given a binary tree and an integer targetSum, return true if the tree has a root -
Question:
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