2017年4月9日21:37:54 145. Binary Tree Postorder Traversal 【】hard
来源:互联网 发布:梦三国矩阵密保卡下载 编辑:程序博客网 时间:2024/06/16 21:53
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]
.
hard题中很简单的二叉树遍历
/**
* 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> postorderTraversal(TreeNode* root) {
vector<int> path;
postOrder(root, path);
return path;
}
void postOrder(TreeNode* root, vector<int> &path)
{
if(root!=NULL)
{
postOrder(root->left, path);
postOrder(root->right, path);
path.push_back(root->val);
}
}
};
一个函数存遍历的数,一个函数遍历 用引用传递保留数据
- 2017年4月9日21:37:54 145. Binary Tree Postorder Traversal 【】hard
- [hard]145. Binary Tree Postorder Traversal
- 145. Binary Tree Postorder Traversal[hard]
- Hard-题目4:145. Binary Tree Postorder Traversal
- Leetcode 145. Binary Tree Postorder Traversal (Hard) (cpp)
- 【LeetCode】145.Binary Tree Postorder Traversal(Hard)解题报告
- [Leetcode 145, Hard] Binary Tree Postorder Traversal
- LeetCode #145 - Binary Tree Postorder Traversal - Hard
- LeetCode145. Binary Tree Postorder Traversal(hard)
- 145.Binary Tree Postorder Traversal
- 145.Binary Tree Postorder Traversal
- 145.Binary Tree Postorder Traversal
- 145. Binary Tree Postorder Traversal
- 145. Binary Tree Postorder Traversal
- 145. Binary Tree Postorder Traversal
- 145. Binary Tree Postorder Traversal
- 145. Binary Tree Postorder Traversal
- 145. Binary Tree Postorder Traversal
- 一篇文章搞懂人工智能、机器学习和深度学习之间的区别
- 思维 CodeForces
- POJ 2253
- 题目1153:括号匹配问题 九度OJ
- JS数组的冒泡排序法
- 2017年4月9日21:37:54 145. Binary Tree Postorder Traversal 【】hard
- Lua5.3遇到的坑
- PAT A1010. Radix PAT和牛客网全A思路以及PAT上测试例10的讨论
- Centos7 搭建 V为P屁N恩
- ava IO的File类常用方法总结三
- effective java 读书笔记---第三章对于所有对象都通用的方法
- 2016东莞市特长生考试 游戏问题
- Median
- Android日历界面MaterialCalendarView的使用