美文网首页
Maximum Depth of Binary Tree - 返

Maximum Depth of Binary Tree - 返

作者: 郑明明 | 来源:发表于2016-10-31 11:47 被阅读70次

本题很简单,如果对递归的思想非常熟悉的,可以很快解出这个题目
直接上代码:

int maxDepth(TreeNode* root) {
        TreeNode *tempTreeNode = root;
        if (tempTreeNode == NULL) {
            return 0;
        }
        int left = maxDepth(tempTreeNode->left);
        int right = maxDepth(tempTreeNode->right);
        return (left > right ? left : right) + 1;
}

相关文章

网友评论

      本文标题:Maximum Depth of Binary Tree - 返

      本文链接:https://www.haomeiwen.com/subject/mpqputtx.html