当前位置:网站首页>leetcode刷题:二叉树03(二叉树的后序遍历)
leetcode刷题:二叉树03(二叉树的后序遍历)
2022-07-01 19:16:00 【涛涛英语学不进去】
145.二叉树的后序遍历
package com.programmercarl.tree;
import java.util.ArrayList;
import java.util.List;
/** * @ClassName PostorderTraversal * @Descriotion TODO * @Author nitaotao * @Date 2022/7/1 15:27 * @Version 1.0 * 145. 二叉树的后序遍历 * https://leetcode.cn/problems/binary-tree-postorder-traversal/ **/
public class PostorderTraversal {
public List<Integer> postorderTraversal(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);
//右
traversal(root.right,result);
//中
result.add(root.val);
}
}
边栏推荐
- 【多线程】 实现单例模式 ( 饿汉、懒汉 ) 实现线程安全的单例模式 (双重效验锁)
- Test of NSI script
- 图片拼图微信小程序源码_支持多模板制作和流量主
- RichView 文档中的 ITEM
- Set object value changes null value object
- Learn white box test case design from simple to deep
- Arduino stepper library drive 28byj-48 stepper motor test program
- [multithreading] realize the singleton mode (hungry and lazy) realize the thread safe singleton mode (double validation lock)
- cocoaPods 添加成功后,导入不了头文件或者not found file 报错
- 天气预报小程序源码 天气类微信小程序源码
猜你喜欢
After adding cocoapods successfully, the header file cannot be imported or an error is reported in not found file
cocoaPods 添加成功后,导入不了头文件或者not found file 报错
How to create a pyramid with openmesh
关联线探究,如何连接流程图的两个节点
Data analysts sound tall? Understand these points before you decide whether to transform
Win11如何取消任务栏隐藏?Win11取消任务栏隐藏的方法
EURA欧瑞E1000系列变频器使用PID实现恒压供水功能的相关参数设置及接线
Arduino stepper library drive 28byj-48 stepper motor test program
Hls4ml reports an error the board_ part definition was not found for tul. com. tw:pynq-z2:part0:1.0.
8K HDR!|为 Chromium 实现 HEVC 硬解 - 原理/实测指南
随机推荐
【多线程】 实现单例模式 ( 饿汉、懒汉 ) 实现线程安全的单例模式 (双重效验锁)
Stack overflow 2022 developer survey: where is the industry going?
Data analysts sound tall? Understand these points before you decide whether to transform
走进如心小镇,数智化变革连接“未来社区”
How can I know if I want to get the preferential link of stock account opening? Is it safe to open an account online?
图片拼图微信小程序源码_支持多模板制作和流量主
想得到股票开户的优惠链接,如何得知?在线开户是安全么?
Review notes of Zhang Haifan in introduction to software engineering (Sixth Edition)
[multithreading] realize the singleton mode (hungry and lazy) realize the thread safe singleton mode (double validation lock)
目標檢測——Yolo系列
internship:逐渐迈向项目开发
宅男壁纸大全微信小程序源码-带动态壁纸支持多种流量主
Arduino Stepper库驱动28BYJ-48步进电机测试程序
Uniapp uses Tencent map to select points without window monitoring to return users' location information. How to deal with it
Items in richview documents
多个张量与多个卷积核做卷积运算的输出结果
Is it safe to open an account online? Can a novice open a stock trading account.
Comprehensive evaluation and detailed inventory of high-quality note taking software (I) note, obsedian, remnote, flowus
漏洞复现-.Net-ueditor上传
STC 32位8051单片机开发实例教程 三 程序编译设置与下载