Skip to content

Practice Binary Tree Tilt

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#563
LeetCode Problem

Binary Tree Tilt

Problem Statement

Given the root of a binary tree, return the sum of every tree node's tilt. The tilt of a tree node is the absolute difference between the sum of all left subtree node values and all right subtree node values. If a node does not have a left child, then the sum of the left subtree node values is treated as 0. The rule is similar if the node does not have a right child.

Source: Binary Tree Tilt on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
root = [1,2,3]
Output
1

# Example 2

Input
root = [4,2,9,3,5,null,7]
Output
15

# Example 3

Input
root = [21,7,14,1,1,2,2,3,3]
Output
9

Constraints

The number of nodes in the tree is in the range [0, 10^4].
-1000 <= Node.val <= 1000

Related LeetCode Problems

Practice more problems similar to Binary Tree Tilt.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.