class Solution {
int ret = 0;
public int diameterOfBinaryTree(TreeNode root) {
findDepth(root);
return ret - 1;
}
private int findDepth(TreeNode root) {
if (root == null) return 0;
int leftPath = findDepth(root.left);
int rightPath = findDepth(root.right);
ret = Math.max(ret, leftPath + 1 + rightPath);
return Math.max(leftPath, rightPath) + 1;
}
}