leetcode563】的更多相关文章

Given a binary tree, return the tilt of the whole tree. The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node values and the sum of all right subtree node values. Null node has tilt 0. The tilt of the …
/** * Definition for a binary tree node. * public class TreeNode { * public int val; * public TreeNode left; * public TreeNode right; * public TreeNode(int x) { val = x; } * } */ public class Solution { /// <summary> /// 遍历二叉树,存储节点列表 /// </summar…
给定一个二叉树,计算整个树的坡度. 一个树的节点的坡度定义即为,该节点左子树的结点之和和右子树结点之和的差的绝对值.空结点的的坡度是0. 整个树的坡度就是其所有节点的坡度之和. 示例: 输入: 1 / \ 2   3 输出: 1 解释: 结点的坡度 2 : 0 结点的坡度 3 : 0 结点的坡度 1 : |2-3| = 1 树的坡度 : 0 + 0 + 1 = 1 注意: 任何子树的结点的和不会超过32位整数的范围. 坡度的值不会超过32位整数的范围. class Solution { publ…
题目 1 class Solution { 2 public: 3 int ans = 0; 4 int findTilt(TreeNode* root) { 5 postOrder(root); 6 return ans; 7 } 8 int postOrder(TreeNode* root){ 9 if(root == NULL) return 0; 10 int leftSum = postOrder(root->left); 11 int rightSum = postOrder(roo…