当前位置:网站首页>Force buckle 145 Binary Tree Postorder Traversal
Force buckle 145 Binary Tree Postorder Traversal
2022-07-07 07:55:00 【Yangshiwei....】
subject :
analysis :
After the sequence traversal , First left node , Rear right node , Finally, its own node , The difference between the first, middle and last traversals is the difference in order , Just exchange the code and position
Code :
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {
public List<Integer> postorderTraversal(TreeNode root) {
List<Integer> list =new ArrayList();
last(root,list);
return list;
}
public void last(TreeNode node,List<Integer> list){
if(node!=null){
if(node.left!=null){
last(node.left,list);
}if(node.right!=null){
last(node.right,list);
}
list.add(node.val);
}
}
}
边栏推荐
- Problem solving: unable to connect to redis
- [Stanford Jiwang cs144 project] lab3: tcpsender
- 通信设备商,到底有哪些岗位?
- LeetCode 40:组合总和 II
- 今日现货白银操作建议
- [Stanford Jiwang cs144 project] lab4: tcpconnection
- 3D reconstruction - stereo correction
- [advanced digital IC Verification] command query method and common command interpretation of VCs tool
- [UVM practice] Chapter 2: a simple UVM verification platform (2) only driver verification platform
- Resource create package method
猜你喜欢
[Matlab] Simulink 自定义函数中的矩阵乘法工作不正常时可以使用模块库中的矩阵乘法模块代替
Explore Cassandra's decentralized distributed architecture
【p2p】本地抓包
解决问题:Unable to connect to Redis
[GUET-CTF2019]虚假的压缩包
2022年茶艺师(中级)考试试题及模拟考试
测试周期被压缩?教你9个方法去应对
[guess-ctf2019] fake compressed packets
After the interview, the interviewer roast in the circle of friends
leetcode:105. Constructing binary trees from preorder and inorder traversal sequences
随机推荐
Use and analysis of dot function in numpy
[CV] Wu Enda machine learning course notes | Chapter 8
[2022 ciscn] replay of preliminary web topics
A bit of knowledge - about Apple Certified MFI
3D reconstruction - stereo correction
Rust Versus Go(哪种是我的首选语言?)
Tongda injection 0day
pytest+allure+jenkins安装问题:pytest: error: unrecognized arguments: --alluredir
Idea add class annotation template and method template
Technology cloud report: from robot to Cobot, human-computer integration is creating an era
Qt学习28 主窗口中的工具栏
2022 recurrent training question bank and answers of refrigeration and air conditioning equipment operation
You Li takes you to talk about C language 6 (common keywords)
Explore Cassandra's decentralized distributed architecture
探索Cassandra的去中心化分布式架构
Few-Shot Learning && Meta Learning:小样本学习原理和Siamese网络结构(一)
Regular e-commerce problems part1
Weibo publishing cases
这5个摸鱼神器太火了!程序员:知道了快删!
Common method signatures and meanings of Iterable, collection and list