【LeetCode】104 Maximum Depth of Binary Tree

来源:互联网 发布:免费下载绘图软件 编辑:程序博客网 时间:2024/06/16 18:17

原题地址:104. Maximum Depth of Binary Tree。

解法

int maxDepth(TreeNode* root) {    if (root == nullptr) {        return 0;    }    else if (root->left == nullptr && root->right == nullptr) {        return 1;    }    return max(maxDepth(root->left), maxDepth(root->right)) + 1;}
原创粉丝点击