package common;
/**
* @author : zhaoliang
* @program :newCoder
* @description : 二叉树的深度
* @create : 2020/12/09 19:44
*/
public class TreeDepth {
public class TreeNode{
int val;
TreeNode left;
TreeNode right;
TreeNode(int val){
this.val = val;
}
}
public int TreeDepth(TreeNode node){
return node==null?0:1+Math.max(TreeDepth(node.left),TreeDepth(node.right));
}
}
常见算法-二叉树的深度
最新推荐文章于 2021-10-17 09:13:44 发布