标签:
public class Solution { private int result = Integer.MIN_VALUE; public int maxPathSum(TreeNode root) { helper(root); return result; } public int helper(TreeNode root) { if (root == null) { return 0; } int left = helper(root.left); int right = helper(root.right); int[] array1 = new int[]{root.val, left + root.val, right + root.val, left + right + root.val}; Arrays.sort(array1); result = Math.max(result, array1[3]); int[] array2 = new int[]{root.val, left + root.val, right + root.val}; Arrays.sort(array2); return array2[2]; } }
[LeetCode]Binary Tree Maximum Path Sum
标签:
原文地址:http://www.cnblogs.com/vision-love-programming/p/5018234.html