- 题目描述
给定一个二叉树,找出其最大深度。
二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。
说明: 叶子节点是指没有子节点的节点。 - c++代码
int maxDepth(TreeNode* root) {
if(root==NULL) return 0;
return max(maxDepth(root->right)+1,maxDepth(root->left)+1);
}
题目链接
https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/