Leetcode | 563. 二叉树的坡度
Posted sunbines
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode | 563. 二叉树的坡度相关的知识,希望对你有一定的参考价值。
测试代码:
1 class Solution { 2 public: 3 int countChild(TreeNode* node) { 4 if (node == nullptr) return 0; 5 return node->val + countChild(node->left) + countChild(node->right); 6 } 7 8 int findTilt(TreeNode* root) { 9 if (root == nullptr) return 0; 10 return abs(countChild(root->left) - countChild(root->right)) + findTilt(root->left) + findTilt(root->right); 11 } 12 };
以上是关于Leetcode | 563. 二叉树的坡度的主要内容,如果未能解决你的问题,请参考以下文章
LeetCode 391. 完美矩形(扫描线) / 318. 最大单词长度乘积 / 563. 二叉树的坡度