[LeetCode 103] Binary Tree Zigzag Level Order Traversal

手把手教你学Simulink--基于光伏(PV)系统的建模与仿真场景:-不同天气条件下光伏系统的输出性能分析 本文介绍了使用Simulink和Simscape Electrical工具箱进行光伏系统建模与仿真的完整流程。内容涵盖准备工作、模型构建、仿真分析三大步骤,重点演示了如何模拟不同天气条件(光照强度、温度变化)对光伏输出性能的影响。通过添加PVArray模块、配置参数、设置环境变化条件、连接测量仪器等操作,实现了光伏系统在动态天气条件下的输出特性分析。文章还提供了仿真参数设置建议和结果分析方法,帮助用户理解环境因素与光伏性能的关联性,为光伏系统设计和优化提供参考。 阅读详情

题目链接:binary-tree-zigzag-level-order-traversal


类似的题型:

1 Binary Tree Level Order Traversal

2 Binary Tree Level Order Traversal II

3 Minimum Depth of Binary Tree

4 Sum Root to Leaf Numbers

5 [LeetCode 101] Symmetric Tree



import java.util.ArrayList;
import java.util.List;

/**
 * 
		Given a binary tree, return the zigzag level order traversal of its nodes' values. 
		(ie, from left to right, then right to left for the next level and alternate between).
		
		For example:
		Given binary tree {3,9,20,#,#,15,7},
		    3
		   / \
		  9  20
		    /  \
		   15   7
		return its zigzag level order traversal as:
		[
		  [3],
		  [20,9],
		  [15,7]
		]
 *
 */

public class BinaryTreeZigzagLevelOrderTraversal {

	public class TreeNode {
		int val;
		TreeNode left;
		TreeNode right;

		TreeNode(int x) {
			val = x;
		}
	}

//	33 / 33 test cases passed.
//	Status: Accepted
//	Runtime: 236 ms
//	Submitted: 0 minutes ago

	//层次遍历法
    public List<List<Integer>> zigzagLevelOrder(TreeNode root) {
        List<TreeNode> stack = new ArrayList<TreeNode>();
        List<List<Integer>> zigzags = new ArrayList<List<Integer>>();
        int level = 0;
        if(root == null) {
        	return zigzags;
        }
        stack.add(root);
        while(!stack.isEmpty()) {
        	List<Integer> zigzig = new ArrayList<Integer>();
        	int size = stack.size();
        	level ++;
        	for (int i = 0; i < size; i++) {
				TreeNode node = stack.remove(0);
				if(node.left != null) {
					stack.add(node.left);
				}
				if(node.right != null) {
					stack.add(node.right);
				}
				if(level % 2 == 1) {
					zigzig.add(node.val);
				} else {
					zigzig.add(0, node.val);
				}
			}
        	zigzags.add(zigzig);
        }
        return zigzags;
    }
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}


Python爬虫实战:如何爬取汽车之家报价信息 本文通过实战介绍了如何使用Python编写爬虫,抓取汽车之家网站的车型、价格、配置等信息。在爬虫实现过程中,我们使用了requests库来发送HTTP请求,使用解析HTML页面,提取嵌入的JSON数据,并将数据存储到CSV文件中。同时,我们还介绍了如何使用反爬虫策略(如随机User-Agent、请求延时、代理池等)来规避反爬虫机制,确保爬虫的稳定性。 阅读详情

相关推荐

核密度估计及其Python实践

一、参数估计简介 很多情况下,我们只有有限的样本集,而类条件概率密度函数p(x|ωi)和先验概率P(ωi)是未知的,需要根据已有样本进行参数估计,然后将估计值当作真实值来使用。 由给定样本集求解随机变量的分布密度函数问题是统计机器学习和概率统计学的基本问题之一。解决该问题的方法包括参数估计和非参数估计两大类: 1.参数估计方法 已知概率密度函数的形式而函数的有关参数未知,通过估计参数来估计概率密度函数的方法。有两种主要参数估计法:确定性参数估计方法是把参数看作确定而未知的, 典型方法为最大似然估计。随机参数

袁易学的博客(Yuan Yixue's Blog) 1万+

【LeetCode】103. Binary Tree Zigzag Level Order Traversal 解题报告

转载请注明出处:http://blog.csdn.net/crazy1235/article/details/51471280Subject 出处:https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/ Given a binary tree, return the zigzag level ord

crazy_jack 9871

IDEA 2023.2.3全平台安装指南:Mac/Windows/Linux一键激活(附最新补丁获取)

本文提供IDEA 2023.2.3在Mac、Windows和Linux三大平台的一键安装与激活指南,包含最新补丁获取方法。详细讲解各系统安装流程、性能调优设置及高效开发技巧,帮助开发者快速配置并提升工作效率。

weixin_28832121的博客 413

LeetCode力扣之103. Binary Tree Zigzag Level Order Traversal

Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary tree [...

LeeWei 223

【100%通过率】华为od统一考试B卷【需要打开多少监视器】JAVA&Go 实现

某长方形停车场,每个车位上方都有对应监控器,当且仅当在当前车位或者前后左右四个方向任意一个车位范围停车时,监控器才需要打开:给出某一时刻停车场的停车分布,请统计最少需要打开多少个监控器

MISAYAONE的博客 1万+

21、深入了解SELinux安全系统与/proc文件系统

本文深入探讨了SELinux安全系统与/proc文件系统的原理及实际应用。详细介绍了SELinux的安全上下文、域转换、运行模式、角色管理以及策略查看工具seinfo的使用;同时解析了/proc文件系统的结构与功能,涵盖进程信息查看、系统资源监控及性能优化方法。结合SELinux与/proc的协同应用,提供了系统问题排查流程与安全管理最佳实践,帮助用户提升Linux系统的安全性与稳定性。

ik678901234的博客 67

[LeetCode] 103. Binary Tree Zigzag Level Order Traversal

原题链接:

Ber03的博客 274

Android 11多窗口+分屏+APP窗口嵌套TaskView实现原理一

然而随着版本的迭代升级,google对分屏的定制差异化也越来越大,Androd 11的分屏用的是split-screen-primary和split-screen-secondary的方式,在systemui中去实现的,其定制化的灵活度不是很高,很多业务都是放到sustemui或者fw去实现,但是随着版本的升高,后面出现了TaskView来替代了老版本的分屏方式,但是Task的核心原理其实和之前的方式是一样的,TaskView来实现分屏。

qq_18420641的博客 2628

LeetCode 103:Binary Tree Zigzag Level Order Traversal

Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given binary

哈哈的个人专栏 2777

基于GEC6818开发板+Linux+Qt设计的智能养老院出入管理系统(195)

当前,传统的养老院出入管理模式普遍存在信息更新滞后、数据统计繁琐、实时监控能力不足等问题,难以满足现代养老机构对安全管理与服务质量提升的需求。本系统设计正是针对这些问题,通过集成先进的硬件设备如高性能GEC6818开发板以及RFID刷卡模块,结合稳定高效的嵌入式Linux操作系统和QT开发框架,构建一套功能齐全、操作直观、响应迅速的智能出入管理系统。 该系统能自动记录并实时显示老人的进出时间,方便管理人员及时了解每位老人的活动轨迹,同时具备强大的后台管理功能,支持管理员便捷地进行老人信息的增删改查操作。通

1079

Matplotlib之bar3d画3D柱状图

3D柱状图通常用于展示数据集中不同分类项的数据大小或数量。与普通的柱状图相比,3D柱状图更适合展示数据的三个维度 3D 柱状图 按行/列涂颜色 柱加阴影、描黑边 自定义座标轴名、刻度标签、范围

我走的每一步都算数 1127

LeetCode—103. Binary Tree Zigzag Level Order Traversal

LeetCode—103. Binary Tree Zigzag Level Order Traversal 题目 https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/description/ 之字形层序遍历二叉树。 思路及解法 因为昨天刚做过层序遍历二叉树的题102. Binary Tree Level ...

pnnngchg的博客 377

docker部署neo4j,设置密码。Neo.ClientError.Security.Unauthorized: The client is unauthorized due to authenti

卷,设置NEO4J_AUTH将不会起作用,因为该数据库已经配置了身份验证。Neo4j Docker 服务将会启动,但您需要使用已与该数据库关联的用户名和密码才能登录。这里,使用了环境变量NEO4J_AUTH,设置了用户名为neo4j,密码为neo4jneo4j。这个命令还是比较全的,包括设置密码,设置端口,挂载外部的数据目录等。原因嘛,就是使用docker创建的neo4j,登录不上。把👆提到的外挂的数据,都清空了,再重新来一遍。有一种情况下,这样设置密码,并不会成功。如果不出意外,目前就算大功告成了。

xiezhipu的博客 571

LeetCode - 103. Binary Tree Zigzag Level Order Traversal

题目 LeetCode - 103. Binary Tree Zigzag Level Order Traversal 题目链接 https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/ 参考博客 https://blog.csdn.net/whutshiliu/article/details/96142289 ...

virgilshi的博客 206

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

LeetCode 103. Binary Tree Zigzag Level Order Traversal

Given a binary tree, return thezigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given binary tre...

qq_39638957的博客 154

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

leetcode 103 —— Binary Tree Zigzag Level Order Traversal

Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given binary

ziquanbang的专栏 250

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

Leetcode 103 Binary Tree Zigzag Level Order Traversal

这是一道二叉树的Z字形遍历的问题。原本觉得不是很难,但中间磕磕绊绊遇到了许多小问题,费了我很大功夫才通过。首先和一般的BFS不同,Z字形遍历需要在一层遍历之后在下一层反向遍历。由于BFS常常用到队列这个数据结构,根据这个特点,我自然而然地想到了用栈来实现这种遍历。因为一层的遍历顺序正好和下一层是反的,先遍历到的结点在下一层是后遍历的。所以利用栈的“后进先出”的性质可以很方便地解决这个问题。由于奇偶...

tjumiao的博客 291

[leetcode]103 Binary Tree Zigzag Level Order Traversal

问题描述: Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given

追梦船的专栏 794

LeetCode103——Binary Tree Zigzag Level Order Traversal

题目链接 Given a binary tree, return thezigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given bina...

星辰的博客 210

LeetCode 103. Binary Tree Zigzag Level Order Traversal 题解

本题是二叉树层序遍历的变种,主要考察对 BFS 的灵活运用。使用标志位控制遍历方向可以在收集完一层后反转,也可以使用双端队列优化注意空树的处理通过本题可以深入理解 BFS 在二叉树遍历中的应用。

cannonjinx的博客 2993

[leetcode] 103. Binary Tree Zigzag Level Order Traversal @ python

原题 Given a binary tree, return the zigzag level order traversal of its nodes’ values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given binary t...

闲庭信步 554

LeetCode No.103 Binary Tree Zigzag Level Order Traversal

LeetCode No.103 Binary Tree Zigzag Level Order Traversal

黄健伟的博客 265

【LeetCode】103. Binary Tree Zigzag Level Order Traversal

【LeetCode】103. Binary Tree Zigzag Level Order Traversal Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next

网瘾少年康复中心 423

Leetcode 103. Binary Tree Zigzag Level Order Traversal 二叉树Zigzag遍历 解题报告

1 解题思想首先这道题和 Leetcode 102. Binary Tree Level Order Traversal 二叉树按层遍历 解题报告 很接近,Zigzag同样是按层遍历,但是区别是对于高度为奇数(从0开始计数的话,则是第1 3 5 7)的层,当层的遍历需要反过来。做法: 1、采用102题目中的方式,无论是DFS还是BFS都行 2、完成1后,对所有奇数层进行翻转这题的写法和102

MebiuW的专栏 1863

C++ Leetcode 103. Binary Tree Zigzag Level Order Traversal

103. Binary Tree Zigzag Level Order Traversal #1、题目大意 Given a binary tree, return the zigzag level order traversal of its nodes’ values. (ie, from left to right, then right to left for the next level ...

chicwzh的博客 437

[leetcode][python] 103. Binary Tree Zigzag Level Order Traversal

103. Binary Tree Zigzag Level Order Traversal 知识点:slack 1. 原题 Given a binary tree, return the zigzag level order traversal of its nodes’ values. (ie, from left to right, then right to left for the ne...

qq_40670635的博客 295
上一篇: [LeetCode 106] Construct Binary Tree from Inorder and Postorder Traversal
下一篇: [LeetCode 147] Insertion Sort List
xiaoo_gan
博客等级 码龄16年 20粉丝 165原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值