leetcode-java-107. Binary Tree Level Order Traversal II

LeetCode 参考 Java版本 LeetCode 400题目 Java版本 (LeetCode is the platform to help you enhance your skills, expand your knowledge and prepare for technical interviews.) 立即下载
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
/*
先层次遍历出list
再让list倒置
 */
 public class Solution {
     public List<List<Integer>> levelOrderBottom(TreeNode root) {
         List<List<Integer>> list = new LinkedList<List<Integer>>();
         Queue<TreeNode> queue = new LinkedList<TreeNode>();

         if(root == null) {
             return list;
         }

         queue.offer(root);

         while(!queue.isEmpty()) {
             int m = queue.size();
             List<Integer> level = new LinkedList<Integer>();

             while(m > 0) {
                 TreeNode node = queue.peek();

                 if(node.left != null) {
                     queue.offer(node.left);
                 }
                 if(node.right != null) {
                     queue.offer(node.right);
                 }

                 level.add(queue.poll().val);
                 m--;
             }
             list.add(level);
         }

         Collections.reverse(list);
         return list;
     }
 }
ArcGIS | 全球新冠肺炎地图数据下载和处理 ArcGIS 阅读详情

相关推荐

步进电机选型避雷手册:为什么你的42HS电机总丢步?从相数、电流到散热全面拆解

本文深入剖析了42HS步进电机在高速或重载下易出现丢步问题的根本原因。文章指出,选型时不应仅关注静态保持转矩,而需重点分析动态矩频曲线、合理匹配驱动器电流与细分数、进行准确的机械传动惯量计算,并有效管理系统共振与散热。通过全面拆解这些关键因素,为工程师提供了实用的选型避雷指南与系统优化方案。

weixin_29275257的博客 97

LeetCode Java刷题笔记—107. 二叉树的层序遍历 II

LeetCode Java刷题笔记—107. 二叉树的层序遍历 II

终生学习践行者 669

永磁同步电机矢量控制——电流内环前馈解耦策略

在采用永磁同步电机矢量控制时,ud和uq的指令值存在耦合项。需要对其进行解耦,目前,常用的解耦设计方法有前馈解耦、偏差解耦以及内模控制,本文主要分享电流内环前馈解耦控制策略。

a12312341ll的博客 8696

LeetCode 107. Binary Tree Level Order Traversal II

Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For example: Given binary tree {3,9,20,#,#,15,7},

parallelyk的专栏 433

从零开始:如何用Python手绘波特图并分析电路稳定性

本文详细介绍了如何使用Python绘制波特图并分析电路稳定性,涵盖从基础理论到实际应用的完整流程。通过NumPy和Matplotlib实现频域分析,包括RC低通滤波器和RLC带通滤波器的案例,以及相位裕度计算等高级技巧,为电子工程师提供了一套高效的电路分析解决方案。

hhh00的博客 374

在Keil下完成一个汇编程序的编写

在学习STM32的路上开始是学的C语言尚未进行对汇编进行学习,因此抽出时间来学习一下在keil下的汇编语言。

Liu-FE的博客 1万+

[Leetcode] 107. 二叉树的层次遍历 II java

和102题类似,区别是要向结果中倒插list 。 [Leetcode] 102. 二叉树的层次遍历 java  给定一个二叉树,返回其节点值自底向上的层次遍历。 (即按从叶子节点所在层到根节点所在的层,逐层从左向右遍历) 例如: 给定二叉树 [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 返回其自底向上...

niceHou666的博客 2130

libcrypto.so.10(OPENSSL_1.0.2)(64bit) is needed by erlang-22.0.7-1.el7.x86_64

今天安装Rabbitmq的 erlang-22.0.7-1.el7.x86_64.rpmrpm包时遇到了这个坑,害找到说是不容易;错误信息在下面; [root@iz2zef7u84js1qeeq00ewwz RabbitMQ]# rpm -ivh erlang-22.0.7-1.el7.x86_64.rpm warning: erlang-22.0.7-1.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 6026dfca: NOKEY error:

qq_45782349的博客 5783

[leetcode-107]Binary Tree Level Order Traversal II(java)

原文链接代码如下:368ms/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class

中华胡杨的专栏 757

OpenMythos深度解析

本文深入解析了kyegomez/OpenMythos项目如何从第一性原理重建Claude Mythos的核心架构。该项目并非直接复制Claude,而是基于公开论文和实验结果推测其可能的设计理念,构建了包含多模态注意力、深度推理引擎、知识检索模块等六大核心组件的模块化架构。重点剖析了分组查询注意力(GQA)的实现细节,展示了KV头扩展等关键技术。该项目已成为大模型开源社区最受关注的研究之一,为理解Claude的架构思想提供了有价值的参考。

Crown_22的博客 518

【XCharts插件】5-2、从Excel中读取数据并更新图表案例(v3.0)

XCharts插件是一款基于UGUI的功能强大、易用、参数可配置的数据可视化图表插件。【Unity3D插件】XCharts插件完全教程《全网最全》-专栏文章目录【XCharts插件】5-1、从Json中读取数据并更新图表案例(v3.0)介绍了如何从Json文件中读取数据,并更新表格,这篇文章就介绍如何从Excel中读取数据,并更新图表吧。

优快云博客专家,Unity3D高级软件工程师,《Unity 3D从入门到实战》作者。 1275

leetcode107 Java

public List<List<Integer>> levelOrderBottom(TreeNode root) { List<List<Integer>> result =new ArrayList(); List<TreeNode> list=new ArrayList(); if (root==null...

weixin_43159910的博客 270

LCZ数据下载及处理-以重庆市为例(完整Python代码)

LCZ数据下载及处理-以重庆市为例(完整Python代码)

WW、forever的博客 613

Java [Leetcode 107]Binary Tree Level Order Traversal II

题目描述: Given a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For example:Given binary tree{3,9,20,#,#...

dkk37351的博客 157

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

【leetcode】107. Binary Tree Level Order Traversal II【java】

Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For example: Given binary tree [3,9,20,null,null,1

陈善亮的博客 499

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

leetcode解题之107 # Binary Tree Level Order Traversal II Java版

leetcode解题之107 # Binary Tree Level Order Traversal II Java版

mine_song的博客 570

[LeetCode] 107. Binary Tree Level Order Traversal II Java

题目: Given a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For example:Given binary tree[3,9,20,nul...

AC616288149的博客 102

Leetcode107.二叉树的层次遍历II Binary Tree Level Order Traversal II(Java)

Leetcode107.二叉树的层次遍历II Binary Tree Level Order Traversal II(Java) ##Tree##, ##Breadth-first Search## 和102.二叉树的层次遍历做法大致相同 不同部分在于对最终的结果List<List<Integer>> res需要使用Collections.reverse()反转一下得到最终结果 **时间复杂度:**O(n) class Solution { public List<L

qq_42411921的博客 145

【LeetCode】 107. Binary Tree Level Order Traversal II 二叉树的层次遍历 II(Easy)(JAVA)

【LeetCode】 107. Binary Tree Level Order Traversal II 二叉树的层次遍历 II(Easy)(JAVA) 题目地址: https://leetcode.com/problems/binary-tree-level-order-traversal-ii/ 题目描述: Given a binary tree, return the bottom-up l...

qq_16927853的博客 181

Leetcode: 107. Binary Tree Level Order Traversal II(JAVA)

【问题描述】 Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For example: Given binary tree {3,9,20

莫名的程序猿 403

LeetCode 107. Binary Tree Level Order Traversal II 二叉树的层次遍历(Java)

题目: Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root). 解答: 解法一: class Solution { public List<List...

qq_41878358的博客 258

leetcode 107. Binary Tree Level Order Traversal II(BFS)(Java和C++)

leetcode 107. Binary Tree Level Order Traversal II(BFS)(Java和C++)

Shauna_Wu的博客 757

Java | LeetCode | 107. Binary Tree Level Order Traversal II | 层序遍历

107. Binary Tree Level Order Traversal II | 层序遍历 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x...

肖胖孩de部落格 158

Java描述 LeetCode,107. Binary Tree Level Order Traversal II 自底向上的层次遍历

大家好,我是河海哥,专注于后端,如果可以的话,想做一名code designer而不是普通的coder,一起见证河海哥的成长,您的评论与赞是我的最大动力,如有错误还请不吝赐教,万分感谢。一起支持原创吧!纯手打有笔误还望谅解。 1-1:description Given the root of a binary tree, return the bottom-up level order traversal of its nodes’ values. (i.e., from left to right, .

人在江湖 465

LeetCode-107. Binary Tree Level Order Traversal II (java)

Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For example: Given binary tree [3,9,20,null,null,1

NOadu的专栏 508

(Java)leetcode-107 Binary Tree Level Order Traversal II(二叉树的层次遍历 II )

经典BFS框架。

不思量 160
上一篇: leetcode-java-106. Construct Binary Tree from Inorder and Postorder Traversal
下一篇: leetcode-java-108. Convert Sorted Array to Binary Search Tree
github_34514750
博客等级 码龄11年 44粉丝 198原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值