LeetCode 559. 【递归】N叉树的最大深度
原题链接
简单
作者:
大明湖的鱼
,
2021-01-16 10:34:57
,
所有人可见
,
阅读 250
/*
// 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) {
vector<int> res;
int max_depth = 0;
if(root == nullptr) return 0;
for(auto it : root->children){
max_depth = max(max_depth,maxDepth(it));
}
return max_depth+1;
}
};