Maximum Depth of Binary Tree

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

    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));
    }

 

posted on 2013-09-12 20:45  waruzhi  阅读(109)  评论(0编辑  收藏  举报

导航