0563. Binary Tree Tilt

https://leetcode.com/problems/binary-tree-tilt

Description

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 there the node does not have a right child.

Example 1:

Example 2:

Example 3:

Constraints:

  • The number of nodes in the tree is in the range [0, 104].

  • -1000 <= Node.val <= 1000

ac

Last updated

Was this helpful?