Root Equals Sum of Children - Problem
You are given the root of a binary tree that consists of exactly 3 nodes: the root, its left child, and its right child.
Return true if the value of the root is equal to the sum of the values of its two children, or false otherwise.
Input & Output
Example 1 — Root Equals Sum
$
Input:
root = [10,4,6]
›
Output:
true
💡 Note:
Root value 10 equals the sum of its children: 4 + 6 = 10
Example 2 — Root Not Equal Sum
$
Input:
root = [5,3,1]
›
Output:
false
💡 Note:
Root value 5 does not equal the sum of its children: 3 + 1 = 4 ≠ 5
Example 3 — Negative Values
$
Input:
root = [1,1,0]
›
Output:
true
💡 Note:
Root value 1 equals the sum: 1 + 0 = 1
Constraints
- The tree consists of exactly 3 nodes: root, left child, and right child
- -100 ≤ Node.val ≤ 100
Visualization
Tap to expand
Understanding the Visualization
1
Input Tree
Binary tree with exactly 3 nodes: [10,4,6]
2
Process
Check if root.val == left.val + right.val
3
Output
Return true if equal, false otherwise
Key Takeaway
🎯 Key Insight: With exactly 3 nodes, we can directly compare the root value with the sum of its children in constant time
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code