题目

代码
class Solution {
public List<List<Integer>> levelOrder(Node root) {
List<List<Integer>> res = new ArrayList<>();
Deque<Node> queue = new ArrayDeque<>();
if(root == null) return res;
queue.add(root);
while(!queue.isEmpty()){
int size = queue.size();
List<Integer> path = new ArrayList<>();
for(int i = 0; i < size; i++){
Node cur = queue.removeFirst();
path.add(cur.val);
for(Node child : cur.children){
queue.addLast(child);
}
}
res.add(path);
}return res;
}
}
结果


1万+

被折叠的 条评论
为什么被折叠?



