现在的位置: 首页 > 综合 > 正文

Leetcode Maximum Depth of Binary Tree

2014年04月05日 ⁄ 综合 ⁄ 共 390字 ⁄ 字号 评论关闭

Maximum Depth of Binary Tree

 

Given a binary tree, find its maximum depth.

The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

求树最大深度,一个递归就可以了。

其本质和求树的高度是一样的。

比求最小深度要容易的多,如果求最小深度就需要额外处理一下,如博客:

http://blog.csdn.net/kenden23/article/details/14126005

//2014-2-16 update
	int maxDepth(TreeNode *root) 
	{
		if (!root) return 0;
		return max(maxDepth(root->left), maxDepth(root->right)) + 1;
	}

抱歉!评论已关闭.