当前位置:网站首页>Leetcode skimming: binary tree 01 (preorder traversal of binary tree)
Leetcode skimming: binary tree 01 (preorder traversal of binary tree)
2022-07-02 00:26:00 【Taotao can't learn English】
144. Preorder traversal of two tree
1. Determine the parameters and return values of recursive functions
2. Determine termination conditions
3. Determine the logic of monolayer recursion
package com.programmercarl.tree;
import java.util.ArrayList;
import java.util.List;
/** * @ClassName PreorderTraversal * @Descriotion TODO * @Author nitaotao * @Date 2022/7/1 15:21 * @Version 1.0 * 144. Preorder traversal of two tree * https://leetcode.cn/problems/binary-tree-preorder-traversal/ **/
public class PreorderTraversal {
/** * The former sequence traversal , Root left and right . * @param root * @return */
public List<Integer> preorderTraversal(TreeNode root) {
List<Integer> result = new ArrayList<>();
traversal(root, result);
return result;
}
/** * The former sequence traversal , Root left and right . * * @param root * @param result * 1. Determine the parameters and return values of recursive functions * 2. Determine termination conditions * 3. Determine the logic of monolayer recursion */
public void traversal(TreeNode root, List<Integer> result) {
// Termination conditions
if (root == null) {
return;
}
// Access root
result.add(root.val);
// Visit the left subtree
traversal(root.left, result);
// Visit the right subtree
traversal(root.right,result);
}
}
边栏推荐
- 【QT】QtCreator卸载与安装(非正常状态)
- Is the securities account given by qiniu business school safe? Where can I open an account
- From 20s to 500ms, I used these three methods
- 【CTF】bjdctf_ 2020_ babystack2
- JS——图片转base码 、base转File对象
- Mysql database driver (JDBC Driver) jar package download
- Node——Egg 创建本地文件访问接口
- Is it safe to choose mobile phone for stock trading account opening in Beijing?
- Linux CentOS7安装Oracle11g的超完美新手教程
- Asp . Text of automatic reply to NETCORE wechat subscription number
猜你喜欢
Kyushu cloud and Intel jointly released the smart campus private cloud framework, enabling new infrastructure for education
heketi 记录
2022 pinduoduo details / pinduoduo product details / pinduoduo SKU details
[Qt] résoudre le problème que Qt msvc 2017 ne peut pas Compiler
Mysql database driver (JDBC Driver) jar package download
PWN attack and defense world cgpwn2
How to improve data quality
export default 导出的对象,不能解构问题,和module.exports的区别
Flow control statement of SQL data analysis [if, case... When detailed]
leetcode96不同的二叉搜索樹
随机推荐
时间复杂度与空间复杂度
Halcon knowledge: an attempt of 3D reconstruction
Using multithreaded callable to query Oracle Database
挖财学堂开户打新债安全可靠嘛?
Digital transformation has a long way to go, so how to take the key first step
Linux CentOS7安装Oracle11g的超完美新手教程
BPR (Bayesian personalized sorting)
LeetCode 0241.为运算表达式设计优先级 - DFS
使用多线程Callable查询oracle数据库
一个实习生的CnosDB之旅
Leetcode medium question sharing (5)
[opencv450] hog+svm and hog+cascade for pedestrian detection
Node -- egg implements the interface of uploading files
Database -- sqlserver details
【CTF】bjdctf_2020_babystack2
export default 导出的对象,不能解构问题,和module.exports的区别
Barbie q! How to analyze the new game app?
It's nothing to be utilitarian!
Use the htaccess file to prohibit the script execution permission in the directory
Jielizhi Bluetooth headset quality control and production skills [chapter]