- 思路
我们就把他当做二叉树,先把二叉树的求深度代码写出来,然后在其每次判断左子树右子树那里改为判断n子树就可以了。
class Solution {
public int maxDepth(Node root) {
if (root == null) {
return 0;
}
int len = root.children.size();
int max = 0, depth = 0;
for (int i = 0; i < len; i++) {
depth = maxDepth(root.children.get(i));
max = depth > max ? depth : max;
}
return max + 1;
}
}
- 补充:访问List元素,get(index)方法。



