public static int height(BinTree T) { if (T == null) { return -1; } else { return Math.max(height(T.left), height(T.right)) + 1; } } /** Return the diameter of T. */ public static int diameter(BinTree T) { if (T == null ) { return 0; } else { int childDiam = Math.max(diameter(T.left), diameter(T.right)); int nodeDiam = 2 + height(T.left) + height(T.right); return Math.max(childDiam, nodeDiam); }
标签:diameter,right,return,int,max,tree,height From: https://www.cnblogs.com/xuenima/p/17447250.html