当前位置: 首页 > >

leetcode559+求N叉树的最大深度,递归和二叉树一样

发布时间:

https://leetcode.com/problems/maximum-depth-of-n-ary-tree/description/


/*
// Definition for a Node.
class Node {
public:
int val;
vector children;

Node() {}

Node(int _val, vector _children) {
val = _val;
children = _children;
}
};
*/
class Solution {
public:
int maxDepth(Node* root) {
if(root==NULL) return 0;
int dep = 0;
for(auto n: root->children){
dep = max(dep, maxDepth(n));
}
return dep+1;
}
};



友情链接: