当前位置:网站首页>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);
}
}

边栏推荐
- 强大的万年历微信小程序源码-支持多做流量主模式
- 网上开户是安全的吗?新手可以开炒股账户吗。
- math_利用微分算近似值
- Tensorflow reports an error, could not load dynamic library 'libcudnn so. eight
- What did you learn about cheating after you went to college?
- 2022/5/23-2022/5/30
- How to turn off the boot auto start software in win11
- 渗透工具-TrustedSec 公司的渗透测试框架 (PTF)
- Keras machine translation practice
- 8K HDR!|为 Chromium 实现 HEVC 硬解 - 原理/实测指南
猜你喜欢

实战项目笔记(一)——虚拟机的创建

走进如心小镇,数智化变革连接“未来社区”

Big factories are wolves, small factories are dogs?

Redis installation and startup in Windows environment (background startup)

Importance of EDA tools to chip industry knowledge popularization

8K HDR!| Hevc hard solution for chromium - principle / Measurement Guide

Vulnerability recurrence - Net ueeditor upload

Past and present life of product modular design

王者战力查询改名工具箱小程序源码-带流量主激励广告

STC 32位8051单片机开发实例教程 二 I/O工作模式及其配置
随机推荐
Win11如何取消任务栏隐藏?Win11取消任务栏隐藏的方法
ORA-01950
新牛牛盲盒微信小程序源码_支持流量变现,带完整素材图片
寫博客文檔
C # joint Halcon application - Dahua camera acquisition class
uniapp使用腾讯地图选点 没有window监听回传用户的位置信息,怎么处理
随机头像大全,多分类带历史记录微信小程序源码_支持流量主
深度学习 常见的损失函数
What did you learn about cheating after you went to college?
switch 有四样写法你知道么
利用QEventLoop实现同步等待槽函数返回
强大、好用、适合程序员/软件开发者的专业编辑器/笔记软件综合评测和全面推荐
喜马拉雅自研网关架构演进过程
What if win11 can't pause the update? Win11 pause update is gray. How to solve it?
2022安全员-A证考题及在线模拟考试
Using qeventloop to realize synchronous waiting for the return of slot function
C#联合halcon应用——大华相机采集类
How to connect the two nodes of the flow chart
【let var const】
After adding cocoapods successfully, the header file cannot be imported or an error is reported in not found file
