没什么说的,要是非说的话,就是:这类题不应该在leetCode上出现。
int maxDepth(TreeNode *root) {
if(root==NULL)
return 0;
int leftDepth=0,rightDepth=0;
if (root->left)
leftDepth = maxDepth(root->left);
if(root->right)
rightDepth = maxDepth(root->right);
return leftDepth>rightDepth?leftDepth+1:rightDepth+1;
}

938

被折叠的 条评论
为什么被折叠?



