当前位置:网站首页>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);
}
}
边栏推荐
猜你喜欢
1592 example 1 King (sgu223 loj10170 luogu1896 increase + / provincial election -) violent thinking pressure DP 01 Backpack
Data analysts sound tall? Understand these points before you decide whether to transform
Détection des cibles - série Yolo
图片拼图微信小程序源码_支持多模板制作和流量主
Learn white box test case design from simple to deep
tensorflow 张量做卷积,输入量与卷积核维度的理解
《软件工程导论(第六版)》 张海藩 复习笔记
独家消息:阿里云悄然推出RPA云电脑,已与多家RPA厂商开放合作
Practical project notes (I) -- creation of virtual machine
On the next generation entrance of the metauniverse -- the implementation of brain computer interface
随机推荐
Principle of motion capture system
[Mysql]安装Mysql5.7
收藏:存储知识全面总结
Getting started with fastdfs
强大的万年历微信小程序源码-支持多做流量主模式
STC 32-bit 8051 single chip microcomputer development example tutorial II i/o working mode and its configuration
深度学习 常见的损失函数
Importance of EDA tools to chip industry knowledge popularization
Uniapp uses Tencent map to select points without window monitoring to return users' location information. How to deal with it
300题线性代数 第四讲 线性方程组
#yyds干货盘点#SQL聚合查询方法总结
[multithreading] lock strategy
柒微自动发卡系统源码
目标检测——Yolo系列
Win11如何取消任务栏隐藏?Win11取消任务栏隐藏的方法
2022/5/23-2022/5/30
How to connect the two nodes of the flow chart
[Blue Bridge Cup web] analysis of the real topic of the 13th Blue Bridge Cup web university group match in 2022
寫博客文檔
Keras机器翻译实战