I am trying to find the diameter of a binary tree (Path length between any two nodes in the tree containing maximum number of nodes.) in java.
my code snippet:
int max=0; public int diameter(Tree root) { if(root==null) return 0; int l=diameter(root.left); int r=diameter(root.right); max=Math.max(max,l+r+1); return l>r:l+1:r+1; }
max is the max diameter.