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

边栏推荐
- 基于图的 Affinity Propagation 聚类计算公式详解和代码示例
- [C language] explain the usage of memset() function in detail
- 目標檢測——Yolo系列
- 300题线性代数 第四讲 线性方程组
- Arduino stepper library drive 28byj-48 stepper motor test program
- Iframe parent-child page communication
- Customize the insertion of page labels and realize the initial search of similar address books
- 小鸟逃票登机,如何反思,应如何解决,飞机为何怕小鸟?
- Problems encountered in installing MySQL in docker Ubuntu container
- 随机头像大全,多分类带历史记录微信小程序源码_支持流量主
猜你喜欢

新版Free手机、PC、平板、笔记本四端网站缩略展示图在线一键生成网站源码

Win11快捷键切换输入法无反应怎么办?快捷键切换输入法没有反应

Realize pyramids through JS (asterisk pyramid, palindrome symmetric digital pyramid)

Win11 how to hide the taskbar? Win11 method to hide the taskbar

天气预报小程序源码 天气类微信小程序源码

Use Zadig to build a continuous delivery platform from 0 to 1

8K HDR!|为 Chromium 实现 HEVC 硬解 - 原理/实测指南

Niuke programming question -- must brush the string of 101 (brush the question efficiently, draw inferences from one instance)

Win11暂停更新点不了怎么办?Win11暂停更新是灰色的如何解决?

数据分析师听起来很高大上?了解这几点你再决定是否转型
随机推荐
C # joint Halcon application - Dahua camera acquisition class
EURA欧瑞E1000系列变频器使用PID实现恒压供水功能的相关参数设置及接线
Win11如何取消任务栏隐藏?Win11取消任务栏隐藏的方法
Hls4ml reports an error the board_ part definition was not found for tul. com. tw:pynq-z2:part0:1.0.
Internship: complex JSON format data compilation interface
docker ubuntu容器中安装mysql遇到的问题
2022/5/23-2022/5/30
Interesting! Database is also serverless!
RichView 文档中的 ITEM
[mysql] install mysql5.7
[Mysql]安装Mysql5.7
How can I know if I want to get the preferential link of stock account opening? Is it safe to open an account online?
网上开户是安全的吗?新手可以开炒股账户吗。
RichView RichEdit SRichViewEdit PageSize 页面设置与同步
2022熔化焊接与热切割上岗证题目模拟考试平台操作
PHP获取微信小程序和小程序商店外链地址
8K HDR!| Hevc hard solution for chromium - principle / Measurement Guide
Review notes of Zhang Haifan in introduction to software engineering (Sixth Edition)
2022安全员-B证考试练习题模拟考试平台操作
math_ Use differentiation to calculate approximate value
