559.Maxmium Depth of N Ary Tree

Last updated

Last updated
/*
// Definition for a Node.
class Node {
public:
int val;
vector<Node*> children;
Node() {}
Node(int _val, vector<Node*> _children) {
val = _val;
children = _children;
}
};
*/
class Solution {
public:
int maxDepth(Node* root) {
if(!root) return 0;
int res=0;
for(auto i:root->children)
res=max(res,maxDepth(i));
return ++res;
}
};