Check whether the root value of a binary tree equals the sum of its two children.
You are given the root of a binary tree with exactly three nodes: a root node and its left and right children.
Determine whether the value stored at the root is equal to the sum of the values stored in its two children.
Return true if the equality holds, otherwise return false.
true if root.val == root.left.val + root.right.val, otherwise false.Example 1
Input
root = [10, 4, 6]
Output
true
Explanation
The root value is 10 and the sum of its children is 4 + 6 = 10.
Example 2
Input
root = [5, 3, 1]
Output
false
Explanation
The root value is 5 but the sum of its children is 3 + 1 = 4.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.