LeetCode--Binary Tree Postorder Traversal
来源:互联网 发布:北京医疗软件开发 编辑:程序博客网 时间:2024/05/22 06:28
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?
/** * Definition for binary tree * 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> res; postorderTraversal(root, res); return res; } void postorderTraversal(TreeNode *root, vector<int>& res) { if(root==NULL) return; postorderTraversal(root->left, res); postorderTraversal(root->right, res); res.push_back(root->val); }};
1 0
- 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
- 【LeetCode】Binary Tree Postorder Traversal
- 使用 CAS 在 Tomcat 中实现单点登录
- C++隐式类型转换
- [深入浅出iOS库]之图形库Core Plot
- nginx upstream timed out 10060错误解决
- 正确使用String、StringBuffer、StringBuilder
- LeetCode--Binary Tree Postorder Traversal
- 当失去深爱的人时
- JavaSript Array
- CListCtrl控件使用方法总结
- 自动生成@3x图插件
- object c_数据类型和运算符
- 一个将小写数字转换成大写数字的工具类
- mybatis配置详解
- 数组游标实现对数组的各种操作(PHP学习)