【leetcode】563. 二叉树的坡度

 

int recursion(struct TreeNode* root,int* sum){
    if(!root) return 0;
    int left=recursion(root->left,sum);
    int right=recursion(root->right,sum);
    (*sum) += abs(left-right);
    return left+right+root->val;
}

int findTilt(struct TreeNode* root){
    int sum=0;
    recursion(root,&sum);
    return sum;
}

 

posted @ 2020-11-30 09:17  温暖了寂寞  阅读(74)  评论(0编辑  收藏  举报