LeetCode 145 : Binary Tree Postorder Traversal
2015-09-22 15:17
477 查看
和先序遍历类似,根节点的操作放在最后间就可。
/**
* 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> path;
vector<int> postorderTraversal(TreeNode* root) {
if(root!=NULL){
postorderTraversal(root->left);
postorderTraversal(root->right);
path.push_back(root->val);
}
return path;
}
};
/**
* 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> path;
vector<int> postorderTraversal(TreeNode* root) {
if(root!=NULL){
postorderTraversal(root->left);
postorderTraversal(root->right);
path.push_back(root->val);
}
return path;
}
};
相关文章推荐
- magento如何实施正确的缓存策略以达到最佳性能
- Objective-C之数据持久化-SQLite
- OpenCV 为啥勾搭上 OpenGL?
- Linux服务器配置for java web
- Jenkins内置环境变量的使用
- html中怎么样让div并排显示
- iOS开发CGD
- Adapter
- 在ubuntu上配置nginx+php+mysql+phpmyadmin
- dubbo源码分析1-reference bean创建
- (乙)1010. 一元多项式求导
- tachyon与hdfs,以及spark整合
- Objective-C之数据持久化-对象归档
- 计算BitmapFactory.Options.inSampleSize的缩放比算法工具
- JVM中类的卸载机制
- SpringMVC中Shiro报错org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible
- 特权级概述(哥子就想知道CPU是如何验证特权级的)GATE+TSS
- ios 开发中遇到的问题总结以及解决方法
- 特权级概述(哥子就想知道CPU是如何验证特权级的)GATE+TSS
- 冒泡排序