/*
// 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;
if((root->children.size()==0)) return 1;
int h=INT_MIN;
for(int i=0;i<root->children.size();i++)
h=max(h,maxDepth(root->children[i]));
return h+1;
}
};
Leecode 559. N 叉树的最大深度 递归
最新推荐文章于 2024-10-07 07:09:00 发布