llllmz

导航

104. 二叉树的最大深度c

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */

int max(int i,int j){
    if(i>j) return i ;
    return j;
}

int maxDepth(struct TreeNode* root) {
    if(!root) return 0;
    return max(maxDepth(root->left),maxDepth(root->right))+1;
}

结果:

posted on 2024-03-05 15:59  神奇的萝卜丝  阅读(11)  评论(0)    收藏  举报