当前位置:网站首页>leetcode刷题:二叉树02(二叉树的中序遍历)
leetcode刷题:二叉树02(二叉树的中序遍历)
2022-07-01 19:16:00 【涛涛英语学不进去】
94.二叉树的中序遍历
package com.programmercarl.tree;
import java.util.ArrayList;
import java.util.List;
/** * @ClassName InorderTraversal * @Descriotion TODO * @Author nitaotao * @Date 2022/7/1 15:32 * @Version 1.0 * https://leetcode.cn/problems/binary-tree-inorder-traversal/ * 94. 二叉树的中序遍历 **/
public class InorderTraversal {
public List<Integer> inorderTraversal(TreeNode root) {
List<Integer> result = new ArrayList<Integer>();
traversal(root, result);
return result;
}
/** * 中序遍历 * @param root * @param result */
public void traversal(TreeNode root, List<Integer> result) {
if(root==null) {
return;
}
//左中右
traversal(root.left, result);
result.add(root.val);
traversal(root.right, result);
}
}
边栏推荐
- Realize pyramids through JS (asterisk pyramid, palindrome symmetric digital pyramid)
- Penetration tools - trustedsec's penetration testing framework (PTF)
- STC 32位8051单片机开发实例教程 二 I/O工作模式及其配置
- 优质笔记软件综合评测和详细盘点(一) Notion、Obsidian、RemNote、FlowUs
- ORA-01950
- Iframe parent-child page communication
- Richview RichEdit srichviewedit PageSize page setup and synchronization
- C # joint Halcon application - Dahua camera acquisition class
- 关联线探究,如何连接流程图的两个节点
- 大厂做狼,小厂做狗?
猜你喜欢
How to turn off the boot auto start software in win11
Error in installing sharp
天气预报小程序源码 天气类微信小程序源码
实战项目笔记(一)——虚拟机的创建
Simple but modern server dashboard dashdot
How to create a pyramid with openmesh
Getting started with fastdfs
cocoaPods 添加成功后,导入不了头文件或者not found file 报错
GaussDB(for MySQL) :Partial Result Cache,通过缓存中间结果对算子进行加速
Richview trvdocparameters page parameter settings
随机推荐
Hls4ml reports an error the board_ part definition was not found for tul. com. tw:pynq-z2:part0:1.0.
Is it safe to open an account online? Can a novice open a stock trading account.
喜马拉雅自研网关架构演进过程
internship:复杂json格式数据编写接口
Détection des cibles - série Yolo
Solve the problem of slow or failed vscode download
三菱PLC FX3U脉冲轴点动功能块(MC_Jog)
《软件工程导论(第六版)》 张海藩 复习笔记
What did you learn about cheating after you went to college?
新版Free手机、PC、平板、笔记本四端网站缩略展示图在线一键生成网站源码
Common components of flask
Richview trvdocparameters page parameter settings
EDA工具对芯片产业的重要性知识科普
Test of NSI script
Use Zadig to build a continuous delivery platform from 0 to 1
牛客编程题--必刷101之字符串(高效刷题,举一反三)
渗透工具-TrustedSec 公司的渗透测试框架 (PTF)
Data analysts sound tall? Understand these points before you decide whether to transform
Arduino Stepper库驱动28BYJ-48步进电机测试程序
[C language] explain the usage of memset() function in detail