[剑指offer] 把二叉树打印成多行

参考代码

```import java.util.ArrayList;
import java.util.Queue;

/*
public class TreeNode {
int val = 0;
TreeNode left = null;
TreeNode right = null;

public TreeNode(int val) {
this.val = val;
}
}
*/
public class Solution {
ArrayList<ArrayList<Integer> > Print(TreeNode pRoot) {
ArrayList<ArrayList<Integer> > res = new ArrayList<ArrayList<Integer> >();
if(pRoot == null)
return res;
ArrayList<Integer> temp = new ArrayList<Integer>();
layer.offer(pRoot);
int start = 0, end = 1;
while(!layer.isEmpty()){
TreeNode node = layer.poll();
start ++;
if(node.left != null)
if(node.right != null)
if(start == end){
start = 0;
temp = new ArrayList<Integer>();
end = layer.size();
}
}
return res;
}
}```

0 条评论

相关文章

1052

java获取当前时间和前一天日期

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request....

2598

java获取当前时间和前一天日期

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request....

4875

1672

二叉树的非递归遍历

二叉树的非递归遍历

1011

3035

3688

842

23710

1414