Binary Tree Maximum Path Sum

来源:互联网 发布:福州淘宝美工在哪里学 编辑:程序博客网 时间:2024/06/03 15:05
class Solution {public:    int maxpath(TreeNode *root,int &maxlocal)    {        if(root==NULL)            return 0;        int local=root->val;        int left=maxpath(root->left,maxlocal);        int right=maxpath(root->right,maxlocal);        if(left>0)             local=local+left;        if(right>0)             local=local+right;        maxlocal=max(local,maxlocal);        return max(max(left,right),0)+root->val;    }    int maxPathSum(TreeNode *root) {        if(root==NULL)            return 0;        int maxlocal=root->val;        maxpath(root,maxlocal);        return maxlocal;    }};
没想到写博客能赚积分,那就多写点。。这题不会,http://blog.csdn.net/sunbaigui/article/details/8980697,估计下次再让我写我还是不会,先留着
0 0
原创粉丝点击