本题很简单,如果对递归的思想非常熟悉的,可以很快解出这个题目
直接上代码:
int maxDepth(TreeNode* root) {
TreeNode *tempTreeNode = root;
if (tempTreeNode == NULL) {
return 0;
}
int left = maxDepth(tempTreeNode->left);
int right = maxDepth(tempTreeNode->right);
return (left > right ? left : right) + 1;
}