# 32.2 把二叉树打印成多行 [NowCoder](https://www.nowcoder.com/practice/445c44d982d04483b04a54f298796288?tpId=13&tqId=11213&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github) ## 题目描述 和上题几乎一样。 ## 解题思路 ```java ArrayList> Print(TreeNode pRoot) { ArrayList> ret = new ArrayList<>(); Queue queue = new LinkedList<>(); queue.add(pRoot); while (!queue.isEmpty()) { ArrayList list = new ArrayList<>(); int cnt = queue.size(); while (cnt-- > 0) { TreeNode node = queue.poll(); if (node == null) continue; list.add(node.val); queue.add(node.left); queue.add(node.right); } if (list.size() != 0) ret.add(list); } return ret; } ```