llllmz

导航

559. N 叉树的最大深度c

/**
 * Definition for a Node.
 * struct Node {
 *     int val;
 *     int numChildren;
 *     struct Node** children;
 * };
 */

int maxDepth(struct Node* root) {
    if(!root) return 0;
    if(root->numChildren==0) return 1;
    int max=0;
    for(int i=0;i<root->numChildren;i++){
        int t=maxDepth(root->children[i])+1;
        if(t>max) max=t;
    }
    return max;
}

 

posted on 2024-03-20 16:44  神奇的萝卜丝  阅读(7)  评论(0)    收藏  举报