public int depth(TreeNode root)
{
if(root==null)
return;
return Math.max(depth(root.left),depth(root.right))+1;//加上根节点的1
}
二叉树最大深度函数
最新推荐文章于 2022-03-25 21:20:29 发布
public int depth(TreeNode root)
{
if(root==null)
return;
return Math.max(depth(root.left),depth(root.right))+1;//加上根节点的1
}