94 - Binary Tree Inorder Traversal

单相PWM整流器的数学模型、工作原理 阅读详情

Given a binary tree, return the inorder traversal of its nodes' values.

For example:
Given binary tree {1,#,2,3},

   1
    \
     2
    /
   3

return [1,3,2].

Note: Recursive solution is trivial, could you do it iteratively?

confused what "{1,#,2,3}" means? > read more on how binary tree is serialized on OJ.


OJ's Binary Tree Serialization:

The serialization of a binary tree follows a level order traversal, where '#' signifies a path terminator where no node exists below.

Here's an example:

   1
  / \
 2   3
    /
   4
    \
     5
The above binary tree is serialized as  "{1,2,3,#,#,4,#,#,5}".

Subscribe to see which companies asked this question

思路分析:

二叉树的中序遍历。

Classic tree operation, recursion is a straightforward idea to solve this problem.
Recursively do:
(1) Visit left child
(2) Output current node
(3) Visit right child
if current node is empty, return.

/*
*/

#include "stdafx.h"
#include <iostream>
#include <vector>

using namespace std;

struct TreeNode
{
	int val;
	TreeNode *left;
	TreeNode *right;
	TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

class Solution_094_BinaryTreeInorderTraversal
{
public:
	void inOrder(TreeNode *root, vector<int> &res)
	{
		if (root != NULL)
		{
			inOrder(root->left, res);
			res.push_back(root->val);
			inOrder(root->right, res);
		}
		
	}

	vector<int> inorderTraversal(TreeNode* root) 
	{
		vector<int> res;

		inOrder(root, res);

		return res;
	}
};


博途PLC如何建立与笔记本电脑端的连接?(新手必会) 对S7-1500PLC下载硬件组态或程序,需要建立PC与PLC的连接。 由于S7-1500CPU都具有PN端口,因此建立PC与S7-1500PLC的连接通常使用工业以太网来实现。 1.使用网线连接PC-PLC 使用网线,一端连接PC的以太网卡端口,另一端连接S7-1500CPU的PN端口。 2.设置本机IP地址 2.1 确认本机要设置的IP地址段 本机IP地址要和PLC程序组态IP地址段前三位保持一致,后一位使用组态中没有用到的IP地址段。如下图所示。 那么看了这个图片应该就知道了,地址应该设置成192. 阅读详情

相关推荐

SAP-PP MD04详解一

MD04是SAP运行MRP后的结果查询事务码,其他功能强大,标准功能比如:查询/更改物料主数据、转换计划订单到生产订单/采购申请、查询/更改各个MRP元素对应的单据等等。而且还可以附加标准的菜单或者自定义添加事务码上去。老铁将做一个MD04详细说明系列,本篇为第一篇之MRP元素说明。 我们来看看MD04基本界面 可以看到主要的数据显示界面,有日期、MRP元素、MRP元素数据、再计划日期、收货/需求、可用数量、工厂、库存地点等栏位。光标定位到MRP元素列,按F1即可看到各类MRP元素的说...

weixin_52158549的博客 1万+

leetcode binary-tree-inorder-traversal(Java)

leetcode题目 binary-tree-inorder-traversal 题目描述 Given a binary tree, return the inorder traversal of its nodes’ values. For example: Given binary tree{1,#,2,3}, 1 \ 2 / 3 return[1,3,2]. Note: ...

聚沙成塔 467

【AAAI2025】【小目标检测】FBRT-YOLO:更快速、更优的实时航拍图像检测方法

FBRT-YOLO是一种新型实时航拍图像检测方法,针对小目标检测的精度与效率平衡问题提出创新解决方案。该方法通过两个轻量级模块显著提升性能:特征互补映射模块(FCM)将浅层空间位置信息深度整合至网络深层,缓解信息失衡;多核感知单元(MKP)采用多尺度卷积增强多目标感知能力。实验表明,在VisDrone、UAVDT和AI-TOD数据集上,FBRT-YOLO在检测精度和速度方面均优于现有实时检测器,特别适用于资源受限的飞行设备。该模型通过精简网络结构,在保持高性能的同时降低了计算负担,为航拍实时检测提供了高效解

weixin_44184852的博客 2909

leetcode 虐我篇之(十五)Binary Tree Inorder Traversal

刚刚做完了二叉树的非递归先序遍历,现在来做做

wosshzhb的专栏 590

YOLOv8中的C2f模块代码详解

在YOLOv8网络结构中,C2f模块(CSP Bottleneck with 2 Convolutions)是一个关键组件,用于实现跨阶段部分聚合

zzzyyy8的博客 3万+

几率大的网络安全面试题(含答案)

其他篇章:Java校招极大几率出的面试题(含答案)----汇总 本文面试题汇总: 防范常见的 Web 攻击 重要协议分布层 arp协议的工作原理 rip协议是什么?rip的工作原理 什么是RARP?工作原理 OSPF协议?OSPF的工作原理 TCP与UDP区别总结 什么是三次握手四次挥手? tcp为什么要三次握手? dns是什么?dns的工作原理 一次完整的HTTP请求过程 Cookies和ses...

睶 6万+

leetcode之binary-tree-inorder-traversal(二叉树中序遍历)

leetcode之binary-tree-inorder-traversal(二叉树中序遍历) 题目 Given a binary tree, return the inorder traversal of its nodes’ values. For example: Given binary tree{1,#,2,3}, return[1,3,2]. Note: Recursive solu...

此心光明,亦复何言~ 1115

uniapp:APP报错Error: Not Found:Page[2][-1,1;-1,1,0,0,2-0] at view.umd.min.js:1(uniApp安卓苹果ios出现一大堆数字错误)

Error: Not Found:Page[2][一串数字] at view.umd.min.js:1,uniapp在APP端运行报错Error: Not Found:Page[2][-1,1;-1,1,0,0,2-0] at view.umd.min.js:1,uniapp真机运行偶尔出现Not Found:Page[2][-1,28] at view.umd.min.js:1,如何解决uniApp app报错:Not found -1,71 at view.umd.min.js:1,uniapp项目在H

✅ 精选推荐文章 3984

[LeetCode]Binary Tree Inorder Traversal

Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,3,2]. Note: Recursive solutio

293

一次搞懂 OData Deep Create:在 ABAP Client Proxy 中优雅完成父子实体的一键插入

摘要: 本文面向熟悉SAP Gateway与OData的ABAP工程师,详解Deep Create的核心概念与实现。Deep Create允许在一次请求中原子化创建主实体及其关联子实体(如Team与Manager),解决多次HTTP请求导致的脏写问题。对比OData v2/v4协议差异后,重点阐述ABAP Client Proxy中通过Data Description Node构造层级数据描述树的方法,包括根/子节点定义、属性对齐及业务数据绑定。提供可复用的ABAP代码骨架,并区分Deep Create与$

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 191

富芮坤fr8008gp 240X280 lvgl项目启动

fr8008gp_240X280_lvgl项目启动

cheng___yi的博客 1758

leetcode学习笔记94 Binary Tree Inorder Traversal

leetcode学习笔记94开始之前问题思考方法1方法2 开始之前 问题 Binary Tree Inorder Traversal Given the root of a binary tree, return the inorder traversal of its nodes’ values. Follow up: Recursive solution is trivial, could you do it iteratively? 思考 基础. 方法1 标准的递归中序遍历. 时间复杂度O(n)O(n

kuma的博客 334

基于STM32L4XX、HAL库的CH182H1以太网收发器(PHY)驱动程序设计

define PHY_REG_PHYSCR 0x12 // PHY特殊控制寄存器。#define PHY_REG_PHYSTS 0x10 // PHY状态寄存器。#define PHY_REG_PHYIDR 0x11 // PHY标识寄存器。#define PHY_REG_ID1 0x02 // PHY标识符1。#define PHY_REG_ID2 0x03 // PHY标识符2。

zhusl6688的博客 409

94. Binary Tree Inorder Traversal

94. Binary Tree Inorder Traversal 1. 问题 Given a binary tree, return the inorder traversal of its nodes’ values. Example: Input: [1,null,2,3] 1 \ 2 / 3 Output: [1,3,2] Follow up: Recursive solution is trivial, could you do it iterativ

遇见你是我最美丽的意外 4281

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

LeetCode-94. Binary Tree Inorder Traversal [C++][Java]

Given therootof a binary tree, returnthe inorder traversal of its nodes' values.

贫道绝缘子的博客 226

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

LeetCode94——Binary Tree Inorder Traversal

题目链接 Given a binary tree, return theinordertraversal of its nodes' values. Example: Input: [1,null,2,3] 1 \ 2 / 3 Output: [1,3,2] Follow up:Recursive solution is trivial, c...

星辰的博客 427

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

【Leetcode】94. Binary Tree Inorder Traversal

递归的过程是,从树根开始一路向左,同时记录住一路经过的节点,直到向左走到null后回退一步,打印节点,接着向其右子树拐过去,继续重复一路向左,直到右子树遍历完后,回退到树根的上一个节点,打印之,再拐入右子树继续重复。所以用栈来模拟的话就是,先从树根出发一路向左,同时将路径上所有节点按顺序入栈,直到走到null,走到null后,栈里弹出来一个节点就可以访问之了,因为其左子树是空。概括起来就是:树根出发,无前驱就向右走,有前驱则找前驱,前驱无桥则搭桥向左走,前驱有桥则拆桥向右走。法3:Morris遍历。

数学、算法爱好者的博客 296

Leetcode94. Binary Tree Inorder Traversal

Leetcode94. Binary Tree Inorder Traversal 文章目录Leetcode94. Binary Tree Inorder Traversal解法一 经典递归解法二 基于栈的遍历解法三 Morris Traversal(利用线索二叉树)图解莫里斯方法C++解法 Given a binary tree, return the inorder traversal of...

magic_jiayu的博客 409

94.Binary Tree Inorder Traversal

// Recursion class Solution { public: vector<int> inorderTraversal(TreeNode *root) { vector<int> res; inorder(root, res); return res; } void inorder(Tre...

weixin_30929011的博客 153

【LeetCode】 94 Binary Tree Inorder Traversal

题目描述 Given the root of a binary tree, return the inorder traversal of its nodes' values. Example 1: Input: root = [1,null,2,3]Output: [1,3,2] Example 2: Input: root = [1,2]Output: [2,1] Example 3:Input: root = []Output: [] Constraints: T...

Vergegenkunft_的博客 212

Leetcode_94_Binary Tree Inorder Traversal

本文是在学习中的总结,欢迎转载但请注明出处:http://blog.youkuaiyun.com/pistolove/article/details/42876657 Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,3,2]. Note: Re

皮斯特劳沃 1746

leetcode No94. Binary Tree Inorder Traversal

Question: Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tree [1,null,2,3], 1 \ 2 / 3 return [1,3,2]. Note: R

Dufre 848

Leetcode 94 Binary Tree Inorder Traversal

Q: Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tree [1,null,2,3], 1 \ 2 / 3 return [1,3,2]. A: /*

Huangyanxl的博客 476
上一篇: 65 - Valid Number(DFA-Deterministic Finite Automaton)
下一篇: 96 - Unique Binary Search Trees
hellochenlu
博客等级 码龄14年 97粉丝 184原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值