Leetcode[145]-Binary Tree Postorder Traversal
2015-06-13 10:10
375 查看
Given a binary tree, return the postorder traversal of its nodes’ values.
For example:
Given binary tree
return
Note: Recursive solution is trivial, could you do it iteratively?
方法一:递归遍历
For example:
Given binary tree
{1,#,2,3},
1 \ 2 / 3
return
[3,2,1].
Note: Recursive solution is trivial, could you do it iteratively?
方法一:递归遍历
/** * 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: vector<int> nums; vector<int> postorderTraversal(TreeNode* root) { postorder(root); return nums; } void postorder(TreeNode * root){ if(root==NULL) return; if(root->left) postorder(root->left); if(root->right) postorder(root->right); nums.push_back(root->val); } };
相关文章推荐
- rabbitmq_坑
- 认识自己——不要小偷小摸不要委屈自己
- 天声人語 20150613
- ActivityManager: Warning: Activity not started, its current task has been brought to the front 的的问题
- FMDB
- 第二段冲刺进程4
- 解析struts.xml
- 分布式Session框架
- 第二段冲刺进程4
- Centos 5.5下安装samba
- PHYSICALLY-BASED 小镇的demo
- android 通过组件属性动态创建控件并设置布局
- 第二阶段冲刺 站立会议04
- 第二阶段冲刺 站立会议03
- nginx支持缓存302重定向后的文件到本地
- ios-day24-01(SQLite数据库之SQL语句:建表、删表、CRUD、主键约束、排序、条件语句等等)
- PCL库依赖第三方库的功能说明--摘录点云库PCL学习教程
- ! Undefined control sequence. \CJK@XXX ...endcsname {`#2}{`#3}\CJK@ignorespaces \fi l.43 \end{document}
- Bootstrap 模态框(Modal)插件
- 读数学之美——统计语言模型(马尔科夫)