当前位置:网站首页>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;
}
}边栏推荐
- php内存管理机制与垃圾回收机制
- Problems faced by cloud XR and main application scenarios of cloud XR
- Mock服务moco系列(一)- 简介、第一个Demo、Get请求、Post请求
- Redis source code and design analysis -- 18. Analysis of redis network connection Library
- [MySQL]数据库中的索引为什么是用B+树来实现? 哈希表/红黑树/B树是否可行呢?
- 越来越成熟的Rust,都应用了哪些场景呢?
- List转换问题
- Auditing相关注解
- SQL optimizer parsing | youth training camp notes
- SQL那些事
猜你喜欢

Idea integrates common functions of SVN code management

Could not stop Cortex-M device! Please check the JTAG cable solution

图的相关操作

Landmark buildings around the world

SQL那些事

Leetcode 101. symmetric binary tree & 100. same tree & 572. Subtree of another tree

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

越来越成熟的Rust,都应用了哪些场景呢?

Wu Enda's machine learning programming operation cannot be suspended pause problem solved

Auditing related notes
随机推荐
Use of join function in MATLAB
乐观锁解析
如何选择数字孪生可视化平台
c语言---25 扫雷游戏
1---电子实物认知
SQL那些事
MySQL数据库常用命令
Use of stm8s003f3 UART
超全Mavan标签详解
专访即构科技李凯:音视频的有趣、行业前沿一直吸引着我
Mock服务moco系列(一)- 简介、第一个Demo、Get请求、Post请求
Introduction to cloud XR and development opportunities of cloud XR in 5g Era
有没有什么不起眼却挣钱的副业?
对角化、A的幂
MySQL 索引优化全攻略
文件基础知识
Leetcode 101. symmetric binary tree & 100. same tree & 572. Subtree of another tree
"Jargon" | what kind of experience is it to efficiently deliver games with Devops?
Drawing PDF tables (I) drawing excel table styles in PDF and downloading them through iText (supporting Chinese fonts)
Oracle import error: imp-00038: unable to convert to environment character set handle