class Solution {
public:
int maxDepth(Node* root) {
if(!root) return 0;
return depth(root);
}
int depth(Node* root)
{
if(!root) return 0;
int max1=0;
for(int i=0;i<root->children.size();i++)
{
int cdepth=depth(root->children[i]);
max1=max(max1,cdepth);//选所有孩子中高度最大的
}
return max1+1;//然后加上自己的高度
}
};
Maximum depth of N-ary tree
Guess you like
Origin blog.csdn.net/qq_44808694/article/details/111472184
Recommended
Ranking