class Solution {
public:
int maxDepth(TreeNode* root) {
if(root == NULL) return 0;
return max(maxDepth(root -> left), maxDepth(root -> right)) + 1;
}
};
二叉树的最大深度等于max(左子树节点数,右子树节点数) + 1
class Solution {
public:
int maxDepth(TreeNode* root) {
if(root == NULL) return 0;
return max(maxDepth(root -> left), maxDepth(root -> right)) + 1;
}
};
二叉树的最大深度等于max(左子树节点数,右子树节点数) + 1