@@ -0,0 +1,1058 @@
+package problems;%0A%0Apublic class BinaryTreeMaximumPathsum %7B%0A%0A    // Definition for binary tree%0A    public class TreeNode %7B%0A        int val;%0A        TreeNode left;%0A        TreeNode right;%0A%0A        TreeNode(int x) %7B%0A            val = x;%0A        %7D%0A    %7D%0A%0A    public int maxPathSum(TreeNode root) %7B%0A        if (root == null)%0A            return 0;%0A        return pathSum(root)%5B1%5D;%0A    %7D%0A%0A    int%5B%5D pathSum(TreeNode r) %7B%0A        int%5B%5D out = new int%5B2%5D; // out%5B0%5D long leg, out%5B1%5D pathSum%0A%0A        int leftMax = 0, rightMax = 0, leftSum = Integer.MIN_VALUE, rightSum = leftSum;%0A        if (r.left != null) %7B%0A            int%5B%5D left = pathSum(r.left);%0A            leftMax = Math.max(0, left%5B0%5D);%0A            leftSum = left%5B1%5D;%0A        %7D%0A        if (r.right != null) %7B%0A            int%5B%5D right = pathSum(r.right);%0A            rightMax = Math.max(0, right%5B0%5D);%0A            rightSum = right%5B1%5D;%0A        %7D%0A%0A        out%5B0%5D = r.val + Math.max(leftMax, rightMax);%0A        out%5B1%5D = Math.max(r.val + leftMax + rightMax, Math.max(leftSum, rightSum));%0A        return out;%0A    %7D%0A%7D%0A

Add Binary Tree Maximum Pathsum