```
public class Solution {
private int max;
public int diameterOfBinaryTree(TreeNode root) {
helper(root);
return max;
}
private int helper(TreeNode root) {
if (root == null) {
return -1;
}
int left = helper(root.left);//single longest path go through roo.left;
int right = helper(root.right);
max = Math.max(max, 2 + left + right);
return 1 + Math.max(left, right);
}
}
```