当前位置:网站首页>Sword finger offer 32 - ii Print binary tree II from top to bottom
Sword finger offer 32 - ii Print binary tree II from top to bottom
2022-07-29 08:35:00 【ThE wAlkIng D】
Title Description

Problem analysis
This problem uses the sequence traversal of breadth first traversal , Use iterative method to traverse ( According to the characteristics of sequence traversal, queues are used for storage )
The difference between this question and the above one is that the output is a two-dimensional linked list , That is, use the result of the previous method , Introduce a layer while Loop through and store the value of each layer
Code instance
class Solution {
public List<List<Integer>> levelOrder(TreeNode root) {
List<List<Integer>> list = new ArrayList<>();
if(root == null){
return null;
}
Queue<TreeNode> que = new LinkedList<TreeNode>();
que.offer(root);
while(!que.isEmpty()){
List<Integer> itemlist = new ArrayList<>();
TreeNode tempnode = queue.poll();
int len = que.size();
while(len > 0){
if(tempnode.left != null){
que.offer(tempnode.left);
}
if(tempnode.right != null){
que.offer(tempnode.right);
}
len--;
}
list.add(itemlist);
}
return list;
}
}
边栏推荐
- DC motor speed regulation system based on 51 single chip microcomputer (use of L298)
- Data warehouse layered design and data synchronization,, 220728,,,,
- Noise monitoring and sensing system
- 2022 Teddy cup data mining challenge C project and post game summary
- Multifunctional signal generator based on AD9850
- Time function in MySQL
- Arfoundation starts from scratch 5-ar image tracking
- Intelligent temperature control system
- Lesson 3 threejs panoramic preview room case
- Flask reports an error runtimeerror: the session is unavailable because no secret key was set
猜你喜欢

WQS binary learning notes

Day15: the file contains the vulnerability range manual (self use file include range)

Data warehouse layered design and data synchronization,, 220728,,,,

pnpm install出现:ERR_PNPM_PEER_DEP_ISSUES Unmet peer dependencies

Smart energy management system solution

Osg3.6.5 failed to compile freetype
![A little knowledge [synchronized]](/img/4d/4a8beee749328b5867b59740fd7e78.png)
A little knowledge [synchronized]

110道 MySQL面试题及答案 (持续更新)

Charging pile charging technology new energy charging pile development

Compatible with cc1101/cmt2300-dp4301 sub-1g wireless transceiver chip
随机推荐
深度学习(2):图片文字识别
Analysis of zorder sampling partition process in Hudi - "deepnova developer community"
The first week of postgraduate freshman training: deep learning and pytorch Foundation
Txt plain text operation
DC motor control system based on DAC0832
Arfoundation Getting Started tutorial 7-url dynamically loading image tracking Library
Node: file write data (readfile, WriteFile), two modes: overwrite and increment
Solve the problem of MSVC2017 compiler with yellow exclamation mark in kits component of QT
Osgsimplegl3 combined with renderdoc tool
Ar virtual augmentation and reality
Osg3.6.5 failed to compile freetype
Application of matrix transpose
Cmake setting vs Startup running environment path
Clickhouse learning (III) table engine
(视频+图文)机器学习入门系列-第3章 逻辑回归
A little knowledge [synchronized]
DAC0832 waveform generator based on 51 single chip microcomputer
Clion+opencv+aruco+cmake configuration
集群使用规范
Inclination sensor accuracy calibration test