public class Solution {
int result = 0;
public int findTilt(TreeNode root) {
postOrder(root);
return result;
}
private int postOrder(TreeNode root) {
if (root == null) return 0;
int left = postOrder(root.left);
int right = postOrder(root.right);
result += Math.abs(left - right);
return left + right + root.val;
}
}
相关文章:
- [LeetCode] Binary Tree Tilt 二叉树的坡度 2021-12-28
- LeetCode算法题-Binary Tree Tilt(Java实现) 2022-01-10
- 二叉树的坡度 | Binary Tree Tilt 2022-12-23
- Binary Tree和Binary Search Tree 2022-12-23
- Binary Tree 2021-11-30
- binary tree 2021-08-19
- Recover Binary Search Tree Validate Binary Search Tree 2022-12-23
- Maximum Binary Tree——tree 2021-10-01