import java.util.ArrayList;
import java.util.LinkedList;
/**
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) {
ArrayList<Integer> ans = new ArrayList<Integer>();
if(root == null) {
return ans;
}
LinkedList<TreeNode> queue = new LinkedList<>();
queue.addLast(root);
while(!queue.isEmpty()) {
int sz = queue.size();
for(int i = 0; i < sz; i++) {
TreeNode tmp = queue.removeFirst();
ans.add(tmp.val);
if(tmp.left != null) queue.addLast(tmp.left);
if(tmp.right != null) queue.addLast(tmp.right);
}
}
return ans;
}
}