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

DFS

posted on 2024-03-13 21:08  神奇的萝卜丝  阅读(9)  评论(0)    收藏  举报