https://blog.youkuaiyun.com/cobbyer/article/details/107244046
// 深度
//(递归方式)获取以root为根节点的子树的深度:从叶子节点到达根节点的最长路径
public int getDept(TreeNode root, int dept){
if(root == null){
return dept;
}
int leftDept = getDept(root.left, dept+1);
int rightDept = getDept(root.right, dept+1);
return Math.max(leftDept, rightDept);
}
// 高度
/**
* (递归方式)求树的高度:从叶子节点到达根节点的最长路径
* @param root
* @return
*/
public int getTreeHeight(TreeNode root) {
if (root == null) {
return 0;
}
int leftHeight = getTreeHeight(root.left);
int rightHeight = getTreeHeight(root.right);
return leftHeight > rightHeight? leftHeight+1 : rightHeight+1;
}