标签:style value tco bsp div logs ret public roo
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ class Solution { private int maxValue = 0; public int diameterOfBinaryTree(TreeNode root) { if (root == null) { return 0; } getDia(root); return maxValue - 1; } private int getDia(TreeNode root) { if (root == null) { return 0; } int left = getDia(root.left); int right = getDia(root.right); maxValue = Math.max(left + right + 1, maxValue); return Math.max(left, right) + 1; } }
LeetCode 543: Diameter of Binary Tree
标签:style value tco bsp div logs ret public roo
原文地址:http://www.cnblogs.com/shuashuashua/p/7468687.html