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