#C14990. Range Sum of a Binary Tree
Range Sum of a Binary Tree
Range Sum of a Binary Tree
You are given a binary tree and two integers \(L\) and \(R\). Your task is to compute the sum of all node values in the binary tree that lie in the inclusive range \([L, R]\). The binary tree is provided in level order format, where the string null
represents a missing node.
The problem requires you to construct the binary tree from the input and then calculate the sum using a recursive approach. A node's value is included in the sum if it satisfies \(L \leq \text{node.val} \leq R\).
inputFormat
The input consists of two lines:
- The first line contains space-separated tokens representing the binary tree in level order. The token
null
indicates that a particular child is missing. - The second line contains two space-separated integers \(L\) and \(R\), which denote the lower and upper bounds of the range (inclusive).
outputFormat
Output a single integer representing the sum of the values of all nodes in the tree that lie within the inclusive range \([L,R]\).
## sample10
5 15
10