【leetcode】N叉树的最大深度

 

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

 

posted @ 2020-09-20 08:54  温暖了寂寞  阅读(163)  评论(0编辑  收藏  举报