当前位置:网站首页>Jz32 print binary tree from top to bottom
Jz32 print binary tree from top to bottom
2022-07-25 18:23:00 【syc596】
JZ32 Print binary tree from top to bottom
Print binary tree from top to bottom _ Niuke Tiba _ Cattle from (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;
}
}边栏推荐
- [haoi2015] tree operation
- 柔性电流探头选型指南
- CircleIndicator组件,使指示器风格更加多样化
- Experimental reproduction of image classification (reasoning only) based on caffe resnet-50 network
- The new version of 3dcat v2.1.3 has been released. You can't miss these three function updates!
- Stm32f105rbt6 internal flash debugging
- Bl602 development environment setup
- [web page performance optimization] what about the slow loading speed of the first screen of SPA (single page application)?
- How to create an effective help document?
- srec_ Use of common cat parameters
猜你喜欢

C language -- 25 minesweeping game

Related operations of figure

There was an error while marking a file for deletion

Related operations of binary tree

408第二章线性表

超全Mavan标签详解

Talking about Devops monitoring, how does the team choose monitoring tools?

Safe operation instructions for oscilloscope probe that must be read by engineers

STM8S003F3 内部flash调试

Oracle导入出错:IMP-00038: 无法转换为环境字符集句柄
随机推荐
Stm8s003f3 internal flash debugging
Design practice of Netease strictly selecting inventory center
Good news! Ruiyun technology was awarded the member unit of 5g integrated application special committee of "sailing on the sea"
UnitTest框架应用
Is it true that CITIC Securities' low commission account opening is free of 5? Is it safe
Tkinter GUI address book management system
Combined with GHS multi, use Reza E1 simulator to realize the simulation and debugging of Reza rh850 single chip microcomputer
[haoi2015] tree operation
Recommend a qinheng Bluetooth reference blog
BiSeNet v1
win11下vscode 自动升级失败 There was an error while marking a file for deletion
Construction of Huffman tree
Tensor to img & imge to tensor (tensor conversion of pytorch)
Boomi won the "best CEO in diversity" and the "best company in career growth" and ranked among the top 50 in the large company category
7. 依赖注入
[QNX Hypervisor 2.2用户手册]9.4 dryrun
BL602 开发环境搭建
pd.melt() vs reshape2::melt()
Safe operation instructions for oscilloscope probe that must be read by engineers
C语言 整数与字符串的相互转换