import java.util.ArrayList;
/**
public class TreeNode {
int val = 0;
TreeNode left = null;
TreeNode right = null;
public TreeNode(int val) {
this.val = val;
}
}
*/
public class Solution {
public ArrayList<Integer> PrintFromTopToBottom(TreeNode root) {
// 判断当root为空的情况
ArrayList<Integer> list = new ArrayList<Integer>();
if(root == null){
return list;
}
// root不为空
ArrayList<TreeNode> tList = new ArrayList<TreeNode>();
tList.add(root);
while(tList.size() != 0){
TreeNode temp = tList.remove(0); // 删除指定索引位置的元素 arraylist.remove(int index)
list.add(temp.val);
if(temp.left != null){
tList.add(temp.left);
}
if(temp.right != null){
tList.add(temp.right);
}
}
return list;
}
}