当前位置:网站首页>JZ32 从上往下打印二叉树
JZ32 从上往下打印二叉树
2022-07-20 21:38:00 【syc596】
JZ32 从上往下打印二叉树
从上往下打印二叉树_牛客题霸_牛客网 (nowcoder.com)
import java.util.*;
import java.util.ArrayList;
import java.util.Queue;
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()){
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;
}
}
边栏推荐
- Origin 2022 download nanny level installation tutorial
- Wechat vaccine appointment applet graduation design (5) assignment book of applet completion work
- [stc15 controls ws2812 RGB color lamp cascade]
- deadlock
- After graduation, the three people in beidatong dormitory went to foreign enterprises, state-owned enterprises and entrepreneurship respectively. What do they regret after 10 years
- In the future, a new way of tourism, VR traveling without leaving home, embracing poetry and distance
- JZ25 合并两个排序的链表
- If no linetype is selected, the reason why cacuilinetypecombobox crashes
- JZ30 包含min函数的栈
- Dama Chapter 8 (data integration and interoperability)
猜你喜欢
Difference between service and systemctl / method of modifying path / a command to view IP address, gateway and DNS server
Solve the problem of error reporting in NPM installation NRM syntaxerror: unexpected token import
Change dimension style text fill color
Visual studio easy to use plug-in sharing
Project summary: document management system
Using go TCP to realize simple online group chat function
What if the download of Duoyu security browser is blocked? Turn off the method of download blocking
Ipaylinks, a cross-border payment integration service, won the 3A Asia Award of the asset!
[Star Project] small hat aircraft War (I)
Dama Chapter 6 (data storage and operation)
随机推荐
C | | structure consortium enumeration type
[JS] event communication
How to modify the default path of CONDA virtual environment
2.8 component life cycle
Translation of UAV intelligent coverage navigation based on DRL in complex geometric environments
Three structures of C language
Why is sha256 irreversible and how secure is sha256
TransUNet: Transformers Make Strong Encoders for Medical Image Segmentation
How cloud primitives support enterprise IT governance | Alibaba cloud user group
Signal integrity (SI) power integrity (PI) learning notes (xxx) power distribution network (II)
【STC15控制WS2812 RGB彩灯级联】
Wechat applet - "data binding and event binding"
In the financial scenario, how to accurately select and quickly implement distributed databases?
2022 Shandong vision prevention and control conference, China eye care products exhibition, Jinan myopia correction equipment exhibition
Tian Wei, architect of Alibaba cloud native application platform: planning, governance and evolution of application architecture
DTOS帝拓思的3D引擎將取代遊戲引擎巨獸,實現國產化替代
Lora base station coverage
Dama Chapter 7 (data security)
Starfish OS: create a new paradigm of the meta universe with reality as the link
Project summary: document management system