版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/glw0223/article/details/88741100
559. N叉树的最大深度
/*
// 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==nullptr){
return 0;
}
int max=1;
vector<Node*>::iterator it=root->children.begin();
for(;it!=root->children.end();it++){
int temp = maxDepth(*it);
if(temp+1>max){
max = temp+1;
}
}
return max;
}
};