博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Maximum Depth of Binary Tree
阅读量:6998 次
发布时间:2019-06-27

本文共 410 字,大约阅读时间需要 1 分钟。

求二叉树的最大深度,入门级别的递归。

int max(int a, int b){        if(a > b)            return a;        return b;    }    int maxDepth(TreeNode *root) {        // Start typing your C/C++ solution below        // DO NOT write int main() function        if(root == NULL)            return 0;        else            return 1+max(maxDepth(root->left), maxDepth(root->right));    }

 

转载于:https://www.cnblogs.com/waruzhi/p/3317745.html

你可能感兴趣的文章