<> Title Description

Print each node of the binary tree from top to bottom , Nodes on the same layer are printed from left to right .

<> Problem solving
import java.util.ArrayList; import java.util.Queue; 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> list = new ArrayList<>(); if(root==null) return list; Queue<TreeNode>
queue= new LinkedList<>(); queue.offer(root); // Executed when the queue is not empty while (!queue.
isEmpty()){ // Take out the element at the top of the queue first list.add(queue.peek().val); // Take out the top element of the queue TreeNode poll
= queue.poll(); // if(poll.left!=null) queue.offer(poll.left); if(poll.right!=
null) queue.offer(poll.right); } return list; } }

Technology
©2020 ioDraw All rights reserved
2020 Nobel Prize in physiology or medicine announced Implementation and challenge of metadata service in data Lake Enterprises face SEM Bidding and SEO How to choose ? Or both ?spark.sql.shuffle.partitions and spark.default.parallelism The difference between JavaScript Do a simple guess number games What are the types of variables ? Trump's "VIP therapy ": Is receiving a drug treatment that has not yet been approved ( Essence )2020 year 6 month 26 day C# Class library DataTable( Extension method ) program ( process ) How is it stored in the operating system , Space allocation Understanding neural network machine translation in three minutes