Root Equals Sum of Children
Trees
EasyLeetCode #2236
Problem Statement
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.
Example
Input: root = [10,4,6]
Output: true
The aue of the root is 10. The sum of its children is 4 + 6 = 10. 10 == 10, so we return true.
Algorithm Explanation
The solution is straightforward. We just need to check if the root's value is equal to the sum of its children's values.
Algorithm Steps
- Access the root's value.
- Access the left child's value.
- Access the right child's value.
- Return `true` if `root.val == root.left.val + root.right.val`, and `false` otherwise.
Start
Checking if root value equals sum of children.
Root Equals Sum of Children Solution