当前位置:网站首页>JZ32 从上往下打印二叉树
JZ32 从上往下打印二叉树
2022-07-25 18:13:00 【syc596】
JZ32 从上往下打印二叉树
从上往下打印二叉树_牛客题霸_牛客网 (nowcoder.com)
import java.util.*;
public class Solution {
public ArrayList<Integer> PrintFromTopToBottom(TreeNode root) {
ArrayList<Integer> list=new ArrayList<>();
if(root==null){
return list;
}
Queue<TreeNode> q=new LinkedList<>();
q.offer(root);
while(q.isEmpty()==false){
TreeNode cur=q.poll();
list.add(cur.val);
if(cur.left!=null){
q.offer(cur.left);
}
if(cur.right!=null){
q.offer(cur.right);
}
}
return list;
}
}边栏推荐
猜你喜欢

关于云XR介绍,以及5G时代云化XR的发展机遇

Pan domain name configuration method

What is the relationship between cloud fluidization and cloud desktop

Keil5 "loading PDSC debug description failed for STMicroelectronics stm32hxxxxxxx" solution

Tme2022 campus recruitment background development / operation development / business operation and maintenance / application development written examination (I) a little self analysis of programming q

Cloud XR面临的问题以及Cloud XR主要应用场景

SQL那些事

408 Chapter 2 linear table

"Digital security" alert NFT's seven Scams

使用sqldeveloper连接mysql
随机推荐
Redistemplate solves the problem of oversold inventory in the seckill system with high speed - redis transaction + optimistic lock mechanism
Auditing related notes
Bl602 development environment setup
Basic knowledge of software testing (mind mapping)
How to read a Book
How to choose digital twin visualization platform
tkinter GUI版通信录管理系统
H5测试点(思维导图)
大话DevOps监控,团队如何选择监控工具?
The new version of 3dcat v2.1.3 has been released. You can't miss these three function updates!
Mock service Moco series (I) - introduction, first demo, get request, post request
如何判断静态代码质量分析工具的性能?这五大因素必须考虑
Could not stop Cortex-M device! Please check the JTAG cable solution
Ch582 ble 5.0 uses Le coded broadcast and connection
Who is responsible for the problems of virtual idol endorsement products?
Which futures account is the best and safest
Li Kai: the interesting and cutting-edge audio and video industry has always attracted me
What is the relationship between cloud fluidization and cloud desktop
有没有什么不起眼却挣钱的副业?
网易严选库存中心设计实践