/*
// 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==NULL){
return 0;
}
int res = 1;
vector<Node*> children = root->children;
for(int i=0;i<children.size();i++){
res = max(res, maxDepth(children[i])+1);
}
return res;
}
};
559. Maximum Depth of N-ary Tree
最新推荐文章于 2024-08-21 10:11:50 发布