LeetCode559.N叉树的最大深度
题目来源:
https://leetcode-cn.com/problems/maximum-depth-of-n-ary-tree/
题目描述:
代码如下:
/*
// Definition for a Node.
class Node {
public int val;
public List<Node> children;
public Node() {}
public Node(int _val,List<Node> _children) {
val = _val;
children = _children;
}
};
*/
class Solution {
public int maxDepth(Node root) {
if (root == null ) { return 0;}
int res = 1;
for (Node node : root.children) {
res = Math.max(res, maxDepth(node) + 1);
}
return res;
}
}