import java.util.ArrayList;
import java.util.*;
/**
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> res = new ArrayList<>();
if (null == root) {
return res;
}
Queue<TreeNode> queue = new LinkedList<>();
TreeNode node = root;
queue.add(node);
while (!queue.isEmpty()) {
node = queue.poll();
res.add(node.val);
if (null != node.left) {
queue.add(node.left);
}
if (null != node.right) {
queue.add(node.right);
}
}
return res;
}
}