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.
//题目要求:给定一棵二叉树,计算其最大深度
//利用递归的方法
class Solution {
public:
int maxDepth(TreeNode* root) {
if (root == NULL) return 0;
while (root != 0){
int m = maxDepth(root->left);
int n = maxDepth(root->right);
return 1 + max(m, n);
}
}
};