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=1;
    for(int i=0;i<root->numChildren;i++){
        int temp=maxDepth(root->children[i])+1;
        if(max<temp) max=temp;
    }
    return max;
}

结果:

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