Maximum Depth of N-ary Tree N叉树的最大深度

/*
// Definition for a Node.
class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
*/
class Solution {
public:
    int maxDepth(Node* root) {
        if(!root) return 0;
        int re=0;
        for(auto& child:root->children) {
            re=max(re,maxDepth(child));
        }
        return re+1;
    }
};

 

posted @ 2020-03-16 17:28  qiujiejie  阅读(85)  评论(0编辑  收藏  举报