论坛备案网站名称网站建设目的内容输出
题目链接:104. 二叉树的最大深度 - 力扣(LeetCode)
最大深度等于左子树的最大深度和右子树的最大深度中的较大者加一
class Solution {
public:int maxDepth(TreeNode *root) {if (!root)return 0;return max(maxDepth(root->left), maxDepth(root->right)) + 1;}
};
题目链接:104. 二叉树的最大深度 - 力扣(LeetCode)
最大深度等于左子树的最大深度和右子树的最大深度中的较大者加一
class Solution {
public:int maxDepth(TreeNode *root) {if (!root)return 0;return max(maxDepth(root->left), maxDepth(root->right)) + 1;}
};