/*递归法。某树的深度为其左右子树深度较大者加1.*/
class Solution {
public:
int maxDepth(TreeNode* root) {
if(root == nullptr) return 0;
return 1 + max(maxDepth(root->left), maxDepth(root->right));
}
};
LeetCode之Maximum Depth of Binary Tree
最新推荐文章于 2024-10-15 15:32:42 发布
