/**
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param root TreeNode类
* @return int整型
*/
int maxpath(struct TreeNode* root,int *maxnew){
int l,r;
if(root->left!=NULL)
l=maxpath(root->left,maxnew);
else l=0;
if(root->right!=NULL)
r=maxpath(root->right,maxnew);
else r=0;
int max=root->val+((l>r)?l:r);
int newpath=root->val+l+r;
*maxnew=(*maxnew>newpath)?*maxnew:newpath;
return max;
}
int maxPathSum(struct TreeNode* root ) {
// write code here
int a=root->val;
int *maxnew=&a;
int max=maxpath(root,maxnew);
return (*maxnew>max)?*maxnew:max;
}