public class Solution
{
public int MaxDepth(TreeNode root)
{
int result=0;
Df(root, ref result,0);
return result;
}
private void Df(TreeNode node,ref int max ,int deep)
{
if (node == null)
return;
deep++;
Df(node.left,ref max,deep);
max = Math.Max(max,deep);
Df(node.right,ref max,deep);
max = Math.Max(max, deep);
}
}
题目给定一个二叉树,找出其最大深度。二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。思路回溯递归 public class Solution { public int MaxDepth(TreeNode root) { int result=0; Df(root, ref result,0);...