Java | Leetcode Java题解之第559题N叉树的最大深度
题目:
题解:
class Solution {
public int maxDepth(Node root) {
if (root == null) {
return 0;
}
Queue<Node> queue = new LinkedList<Node>();
queue.offer(root);
int ans = 0;
while (!queue.isEmpty()) {
int size = queue.size();
while (size > 0) {
Node node = queue.poll();
List<Node> children = node.children;
for (Node child : children) {
queue.offer(child);
}
size--;
}
ans++;
}
return ans;
}
}
原文地址:https://blog.csdn.net/m0_57195758/article/details/143699496
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!