、
二叉树的深度,依旧用递归去解决。
//空树
if(root == null) return 0;
/*
* 解决方案:递归解决
*/
//分别判断左右子树为空
else if(root.left == null && root.right == null)
{
return 1;
}
else if(root.left != null && root.right == null)
{
return 1 + TreeDepth(root.left);
}
else
{
return TreeDepth(root.left) > TreeDepth(root.right) ? 1 + TreeDepth(root.left): 1 + TreeDepth(root.right);
}