Binary Tree Postorder Traversal
来源:互联网 发布:手机怎么上电脑版淘宝 编辑:程序博客网 时间:2024/05/17 17:44
一、问题描述
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]
.
二、思路
二叉树的后续遍历,非递归遍历稍微复杂一点,需要另外设置一个数据结构,改天补上,未完待续。
三、代码
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: void postorder(TreeNode* node,vector<int> &res){ if(!node){ return ; }else{ postorder(node -> left,res); postorder(node -> right,res); res.push_back(node -> val); } } vector<int> postorderTraversal(TreeNode* root) { vector<int> vec; postorder(root,vec); return vec; }};
0 0
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- BZOJ1003: [ZJOI2006]物流运输 Spfa+DP
- android打包准备:混淆第三方jar包(Gson, greenDao,sharesdk,UIL,高德地图, unity,pinyin4j,async http,JPush,EventBus等)
- 连马云都自愧不如 真正的草根创业者
- The Six Best Practices(4~6)
- 关系数据库的模式分解:FD和BCNF、3NF以及MVD和4NF
- Binary Tree Postorder Traversal
- UVA 12105 Bigger is Better
- setsocket函数详解
- Grid Control中进行Dataguard切换 因RAC节点的oracle用户密码不一致导致无法切换
- 百度地图开发 添加覆盖物 + 地理编码和反地理编码
- Activity 如何获取到各种服务service
- TextView如何给其中的某一段文字添加颜色?
- ubuntu16.04 安装配置 mentohust 登录校园网
- 2016年国内多用户系统集合