A root-to-leaf path starts at the root and ends at a leaf, following child links. Given a target integer, decide whether at least one root-to-leaf path has node values that add up to exactly the target.
Input format
One line: the binary tree as a level-order array.
The tree is encoded on ONE line as a space-separated level-order (breadth-first) array. The token null marks a missing child; the children of a null are omitted from the array. An empty tree is written as the single token null.
The next line: an integer target.
Output format
Print YES if some root-to-leaf path sums to the target, otherwise NO. An empty tree has no root-to-leaf path, so its answer is always NO.
Constraints
- The tree has between 0 and 1000 nodes.
- Each node value is an integer with absolute value at most 1000.
- The target is an integer with absolute value at most 1000000.