原题题目
代码实现(首刷半看解半自解)
/*** Definition for a binary tree node.* struct TreeNode {* int val;* struct TreeNode *left;* struct TreeNode *right;* };*/
#define INF 100000
int maxV;void visit(struct TreeNode* root,int max,int min)
{
if(root){
if(root->val > max)max = root->val;if(root->val < min)min = root->val;int temp = max - min;temp > maxV ? maxV = temp : maxV;visit(root->left,max,min);visit(root->right,max,min);}
}int maxAncestorDiff(struct TreeNode* root){
maxV = -1;visit(root,-1,INF);return maxV;
}