C代码:
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;
}