算法第十一周作业01
来源:互联网 发布:led电子屏编辑软件 编辑:程序博客网 时间:2024/06/07 07:04
Description
Given a binary tree, return the postorder traversal of its nodes’ values.
For example:
Given binary tree {1,#,2,3},
1
\
2
/
3
return [3,2,1]
Solution
- 先遍历左子树,后遍历右子树,最后是自身节点
- 按照遍历的顺序将结果添加到List中
- 递归边界:当前节点为null;操作:创建空的链表List
Code
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */import java.util.*;public class Solution { public List<Integer> postorderTraversal(TreeNode root) { if(root != null){ List<Integer> left = postorderTraversal(root.left); List<Integer> righ = postorderTraversal(root.right); left.addAll(righ); left.add(root.val); return left; } else { return new LinkedList<Integer>(); } }}
0 0
- 算法第十一周作业01
- 算法作业_19(2017.5.3第十一周)
- 算法作业_20(2017.5.4第十一周)
- 第十一周作业 1
- 第十一周作业 2
- 第十一周作业 3.0
- 第十一周作业
- 第十一周作业2
- 第十一周作业
- 第十一周作业2
- 第十一周作业 1
- 第十一周java作业
- 第十一周作业
- 第十一周java作业
- 算法第一周作业01
- 算法结构与设计基础作业第十一周
- 算法课第十一周作业 | Longest Consecutive Sequence
- 算法第十周作业01
- 剑指offer-面试题8-旋转数组的最小数字
- .htaccess技巧: URL重写(Rewrite)与重定向(Redirect)
- 数据类型二 运算符、表达式(预习)
- 第十三单元搭建第三方软件仓库
- Python中深拷贝与浅拷贝的区别:
- 算法第十一周作业01
- 子树
- oracle开窗函数over(partition by)函数整理
- 智能卡 7816协议
- 数据统计分析——基本概念_01
- 包含ICE3.5.1的项目从Eclipse4.5转移到AndroidStudio2.1.2操作步骤
- SQLITE3使用总结(二)
- 剑指offer:B是不是A的子树
- TensorFlow 莫烦 手写识别 cross_entry (五)