We’re preparing your current view and syncing the latest data.
Given a binary tree, determine if the value of each non-leaf node is equal to the sum of the values of its left and right child nodes. If a child is missing, consider its value as 0 for the sum. Return true if the condition holds for every non-leaf node in the tree, otherwise return false.
The input is the root of a binary tree.
Return true if every non-leaf node's value is equal to the sum of its children; otherwise, return false.
The number of nodes in the tree is in the range [1, 10^4]. Node values can be any integer.
Example 1
Input
root = [10,4,6]
Output
true
Explanation
Node 10 equals sum of 4 and 6; both 4 and 6 are leaf nodes.
Example 2
Input
root = [10,4,5]
Output
false
Explanation
Node 10 does not equal sum of 4 and 5.