剑指offer 32 - II. 从上到下打印二叉树 II 题目描述 解题思路 class Solution { public List<List<Integer>> levelOrder(TreeNode root) { List<List<Integer>> res = new ArrayList<>(); Queue<TreeNode> queue = new LinkedList<>(); if (root != null) queue.offer(root); while (!queue.isEmpty()) { //保存当前层的节点 List<Integer> temp = new ArrayList<>(); int size = queue.size(); for (int i = 0; i < size; i++) { TreeNode currNode = queue.poll(); //保存结果 temp.add(currNode.val); //左右孩子入队 if (currNode.left != null) queue.offer(currNode.left); if (currNode.right != null) queue.offer(currNode.right); } res.add(temp); } return res; } }