后根遍历

 * struct TreeNode {
 *	int val;
 *	struct TreeNode *left;
 *	struct TreeNode *right;
 * };
 */

class Solution {
public:
    /**
     * 
     * @param root TreeNode类 
     * @return int整型
     */
    void help(TreeNode* root,int &res){
        if(root==NULL) return ;
        help(root->left,res);
        help(root->right,res);
        int l=0,r=0;
        if(root->left&&root->left->val>0) l=root->left->val;
        if(root->right&&root->right->val>0) r=root->right->val;
        res=max(res,root->val+r+l);
        root->val+=max(l,r);
    }
    int maxPathSum(TreeNode* root) {
        // write code here
        int res=INT_MIN;
        help(root,res);
        return res;
    }
};