563. 二叉树的坡度
C代码:
int sum;
int dfs(struct TreeNode* root) {
if (root == NULL) {
return 0;
}
int left = dfs(root->left);
int right = dfs(root->right);
sum += fabs(left - right);
return root->val + left + right;
}
int findTilt(struct TreeNode* root){
sum = 0;
dfs(root);
return sum;
}