一、题目
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from theroot node down to the farthest leaf node.
二、代码
class Solution {
public:
int maxDepth(TreeNode* root) {
if (root==NULL) return 0;
return max(maxDepth(root->left),maxDepth(root->right))+1;
}
};
三、思路
左右子树递归到空节点