当前位置:网站首页>Niuke-top101-bm26
Niuke-top101-bm26
2022-06-21 06:17:00 【A fish that eats cats】
The core idea : Non recursive sequence traversal
import java.util.*;
/* * public class TreeNode { * int val = 0; * TreeNode left = null; * TreeNode right = null; * } */
public class Solution {
/** * * @param root TreeNode class * @return int integer ArrayList<ArrayList<>> */
public ArrayList<ArrayList<Integer>> levelOrder (TreeNode root) {
// write code here
ArrayList<ArrayList<Integer>> lists = new ArrayList<>();
Deque<TreeNode> deque = new ArrayDeque<>();
deque.addLast(root);
while(!deque.isEmpty()){
ArrayList<Integer> list = new ArrayList<>();
int size = deque.size();
for(int i = 0; i < size; i++){
TreeNode t = deque.pollFirst();
list.add(t.val);
if(t.left != null){
deque.addLast(t.left);
}
if(t.right != null){
deque.addLast(t.right);
}
}
lists.add(list);
}
return lists;
}
}
边栏推荐
- [JVM] method area
- [data mining] final review Chapter 1
- FPGA - 7系列 FPGA SelectIO -01- 简介与DCI技术简介
- [data mining] final review Chapter 5
- docker 安装mysql
- Aurora 8b10b IP use - 02 - IP function design skills
- FPGA - 7系列 FPGA SelectIO -05- 逻辑资源之OLOGIC
- tf. contrib. slim. conv2d()
- MSF内网渗透
- Leetcode刷題 ——— (4)字符串中的第一個唯一字符
猜你喜欢

Pyshark tutorial

【【毕业季·进击的技术er】------老学长心得分享

记录 Navicat 连接 PostgreSQL 无法显示对应表的问题

智能需要身体吗

FPGA - 7 Series FPGA selectio -02- introduction to source language

C language course design (detailed explanation of clothing management system)

【JVM】方法区

Contos7 installing SVN server

Solve the first problem of Huawei's machine test on April 20 by recursion and circulation (100 points)

Error running code generator file: the server time zone value ' й ��� ʱ ��‘ is unrecognized or represents more than one time
随机推荐
scala中函数和方法
用递归和循环两种方法解决华为4月20日机试第一题(100分)
fastdfs集群
Contos7 installing SVN server
Which is better for children's consumption type serious diseases at present? Are there any recommended children's products
第二章:数据模型(数据库期末复习)
WordPress pseudo original tool - update website one click pseudo original publishing software
R statistical plot - correlation of environmental factors +mantel test combination diagram (linket package introduction 1)
对网页 ‘’为所欲为‘’ 之手动实现 csdn深色模式?
Microbial ecological data analysis - redundancy analysis
FPGA - 7系列 FPGA SelectIO -02- 源语简介
【数据挖掘】期末复习 第二章
tf.AUTO_REUSE作用
双调查找:数组先递增后递减
Solve the first problem of Huawei's machine test on April 20 by recursion and circulation (100 points)
构建和保护小型网络考试
Pycharm的快捷键Button 4 Click是什么?
数字信号处理-07-DDS IP应用实例
[JVM] classloader
[data mining] final review Chapter 5