/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
int ans=0;
public int diameterOfBinaryTree(TreeNode root) {
depth(root);
return ans;
}
public int depth(TreeNode root){
if(root==null) return 0;
int x=depth(root.left);
int y=depth(root.right);
ans=Math.max(ans,x+y);
return Math.max(x,y)+1;
}
}