//url:https://leetcode.com/problems/maximum-depth-of-n-ary-tree/description/
/*
// Definition for a Node.
class Node {
public:
int val;
vector children;
Node() {}
Node(int _val, vector _children) {
val = _val;
children = _children;
}
};
*/
class Solution {
public:
void getDepth(Node* root,int &depth,int level){
if(!root)
return;
level++;
depth=depth>level?depth:level;
for(int i=0;ichildren.size();i++)
getDepth(root->children[i],depth,level);
}
int maxDepth(Node* root) {
int max=0;
getDepth(root,max,0);
return max;
}
};