码迷,mamicode.com
首页 > 其他好文 > 详细

Leetcode | 563. 二叉树的坡度

时间:2018-09-18 19:22:31      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:style   rip   int   二叉树   ntc   ble   val   color   find   

题目: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. 二叉树的坡度

标签:style   rip   int   二叉树   ntc   ble   val   color   find   

原文地址:https://www.cnblogs.com/sunbines/p/9670077.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!