当前位置:网站首页>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);
}
}
边栏推荐
- 【C语言】详解 memset() 函数用法
- 新版Free手机、PC、平板、笔记本四端网站缩略展示图在线一键生成网站源码
- Getting started with fastdfs
- NSI脚本的测试
- Past and present life of product modular design
- [multithreading] realize the singleton mode (hungry and lazy) realize the thread safe singleton mode (double validation lock)
- 2022/6/8-2022/6/12
- STC 32-bit 8051 single chip microcomputer development example tutorial II i/o working mode and its configuration
- Internship: gradually moving towards project development
- Simple but modern server dashboard dashdot
猜你喜欢
《软件工程导论(第六版)》 张海藩 复习笔记
由浅入深学会白盒测试用例设计
3D panoramic model display visualization technology demonstration
uniapp使用腾讯地图选点 没有window监听回传用户的位置信息,怎么处理
Items in richview documents
随机头像大全,多分类带历史记录微信小程序源码_支持流量主
独家消息:阿里云悄然推出RPA云电脑,已与多家RPA厂商开放合作
Comprehensive evaluation and detailed inventory of high-quality note taking software (I) note, obsedian, remnote, flowus
大厂做狼,小厂做狗?
Practical project notes (I) -- creation of virtual machine
随机推荐
天气预报小程序源码 天气类微信小程序源码
Win11 how to hide the taskbar? Win11 method to hide the taskbar
300题线性代数 第四讲 线性方程组
Items in richview documents
cocoaPods 添加成功后,导入不了头文件或者not found file 报错
uniapp使用腾讯地图选点 没有window监听回传用户的位置信息,怎么处理
8K HDR!| Hevc hard solution for chromium - principle / Measurement Guide
数据分析师听起来很高大上?了解这几点你再决定是否转型
Powerful, easy-to-use, professional editor / notebook software suitable for programmers / software developers, comprehensive evaluation and comprehensive recommendation
Problems encountered in installing MySQL in docker Ubuntu container
3D panoramic model display visualization technology demonstration
新版Free手机、PC、平板、笔记本四端网站缩略展示图在线一键生成网站源码
Optimization of the problem that the request flow fails to terminate during page switching of easycvr cluster video Plaza
fastDFS入门
Win11快捷键切换输入法无反应怎么办?快捷键切换输入法没有反应
Oracle deadlock test
RichView TRVDocParameters 页面参数设置
[multithreading] lock strategy
Keras machine translation practice
极客DIY开源方案分享——数字幅频均衡功率放大器设计(实用的嵌入式电子设计作品软硬件综合实践)