Leetcode Binary Tree Postorder Traversal
来源:互联网 发布:mac如何隐藏菜单栏 编辑:程序博客网 时间:2024/05/22 14:50
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 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> result; postorder(root,result); return result; } void postorder(TreeNode* root,vector<int>& result) { if(root == NULL) return; postorder(root->left,result); postorder(root->right,result); result.push_back(root->val); } };
迭代大法代码如下:
阅读全文
0 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
- 关押罪犯--NOIP2013
- Python-第三方库requests详解
- ThinkPhp 3.1 路由简单配置及URL规则
- Spring Boot 学习第二步 配置MySQL数据库+JPA
- 最高法院法官:关于民间借贷的13个问题
- Leetcode Binary Tree Postorder Traversal
- jquery的搜索框输入提示页面
- .9.png-[Android_YangKe]
- python使用中的小坑
- 第一次接触maven,快速搭建篇
- Spring事务传播性与隔离级别
- Android Hierarchy Viewer位置
- mycat读写分离
- 阿里云ECS CentOS 7 安装图形化桌面