[leetcode]: 104. Maximum Depth of Binary Tree
1.题目描述
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.
求一个二叉树的最大深度
2.分析
可以深度优先搜索或广度优先搜索。
3.代码
深搜,递归,c++
int maxDepth(TreeNode* root) {
if (root == NULL)
return 0;
else
return 1 + max(maxDepth(root->left), maxDepth(root->right));
}
还没有评论,来说两句吧...