二叉树的后序遍历
来源:互联网 发布:考研英语网络课 编辑:程序博客网 时间:2024/06/12 00:44
class Solution { /** * @param root: The root of binary tree. * @return: Postorder in vector which contains node values. */public:vector<int>ans; vector<int> postorderTraversal(TreeNode *root) { // write your code here if(root==NULL)return ans;postorderTraversal(root->left);postorderTraversal(root->right);ans.push_back(root->val);return ans; }};
二叉树的后序遍历
给出一棵二叉树,返回其节点值的后序遍历。
样例
给出一棵二叉树 {1,#,2,3}
,
1 \ 2 / 3
返回 [3,2,1]
解题思路:dfs遍历后序结构访问即可
0 0
- 二叉树的后序遍历
- 二叉搜索树的后序遍历
- 二叉搜索树的后序遍历
- 二叉树的后序遍历
- 二叉搜索树的后序遍历
- 二叉树的后序遍历算法
- 题目:二叉树的后序遍历
- LintCode -- 二叉树的后序遍历
- Lintcode 二叉树的后序遍历
- 二叉搜索树的后序遍历
- LintCode:二叉树的后序遍历
- 二叉树的后序遍历
- 二叉查找树的后序遍历
- 二叉搜索树的后序遍历
- lintcode,二叉树的后序遍历
- 后序二叉线索树的遍历
- 【数据结构】二叉树的后序遍历
- LintCode-二叉树的后序遍历
- 大整数排序
- 编写gSoap XML/RPC程序时出现“soapStub.h: error: redefinition of parameter ‘soap’”
- Connection to localhost:5432 refused. Check that the hostname and port are correct and that the post
- Linux下使用popen()执行shell命令
- 《HTTP权威指南》读书笔记(一):初探缓存
- 二叉树的后序遍历
- 动手写window程序
- @Retention注解
- 一个测试任务并发执行时间的方法
- Java8中的forEach方法详解
- 使用feign调用restful服务
- 什么是java的反射
- Unity Input
- 读书笔记-《Spring技术内幕》-计文柯(一):IoC容器的实现