LeetCode No145 Binary Tree Postorder Traversal
来源:互联网 发布:地形图矢量化软件 编辑:程序博客网 时间:2024/06/08 08:51
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]
.
Note: Recursive solution is trivial, could you do it iteratively?
====================================================================================
题目链接:https://leetcode.com/problems/binary-tree-postorder-traversal/
题目大意:求一个二叉树的后续遍历。
思路:递归。
附上代码:
/** * 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> ans ; if ( root == NULL ) return ans ; postOrder ( root, ans ) ; return ans ; } void postOrder ( TreeNode* root , vector <int>& ans ) { if ( root == NULL ) return ; postOrder ( root -> left , ans ) ; postOrder ( root -> right , ans ) ; ans.push_back ( root -> val ) ; }};
0 0
- LeetCode No145 Binary Tree Postorder Traversal
- LeetCode Binary Tree Postorder Traversal
- LeetCode:Binary Tree Postorder Traversal
- Leetcode: Binary Tree Postorder Traversal
- Leetcode: Binary Tree Postorder Traversal
- LeetCode:Binary Tree Postorder Traversal
- Leetcode Binary Tree Postorder Traversal
- [LeetCode]Binary Tree Postorder Traversal
- [LeetCode] Binary Tree Postorder Traversal
- leetcode Binary Tree Postorder Traversal
- 【LeetCode】Binary Tree Postorder Traversal
- LeetCode | Binary Tree Postorder Traversal
- Leetcode: Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal - LeetCode
- LeetCode - Binary Tree Postorder Traversal
- [LeetCode]Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal -- LeetCode
- [LeetCode]Binary Tree Postorder Traversal
- tolua学习资料汇总贴
- 【LeetCode】3Sum,3Sum Closest 题解报告
- mysql merge
- Quartz配合Spring使用的一种方法
- NOIP 2005 等价表达式
- LeetCode No145 Binary Tree Postorder Traversal
- JAVA 异常
- Angular2中使用bootstrap
- POJ 2418Hardwood Species(搜索二叉树)
- BST iterator
- 51nod 1013 3的幂数和(快速幂+费马小定理)
- Android listview或者xlisview或者Recyclerview 点击item没反应
- 洛谷 P1199 三国游戏
- Commands out of sync; you can't run this command now