`
bcyy
  • 浏览: 1832017 次
文章分类
社区版块
存档分类
最新评论

Leetcode Maximum Depth of Binary Tree

 
阅读更多

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;
	}



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics