Binary Tree Postorder Traversal
来源:互联网 发布:ios远程访问mac 编辑:程序博客网 时间:2024/06/05 05:46
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?
后序遍历,不能使用递归
class Solution {public: vector<int> postorderTraversal(TreeNode *root) { vector<int> rel; if(root==NULL) return rel; s.push(*root); while(!s.empty()) { TreeNode & v = s.top(); if(v.right==NULL && v.left==NULL) { rel.push_back(v.val); s.pop(); } else { if(v.right!=NULL) { s.push(*v.right); v.right = NULL; } if(v.left!=NULL) { s.push(*v.left); v.left = NULL; }; } } return rel; } stack<TreeNode> s;};
0 0
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- 10个实用的Django建议
- GO环境设置
- GIT的操作流程图
- 分享Django Introduction PPT
- UA888 ,UA223 and UA5478
- Binary Tree Postorder Traversal
- 用solr uuid解决多表导入数据库问题
- oracle导入导出
- windows进程间通信
- C++教材
- Django 分页插件:django-pagination .
- configure: error: Package requirements (glib-2.0 >= 2.10.1 gmodule-2.0 gthread-2.0) were not met:
- 发的抚摸对方浪费吗都看什么塞德里克塞德里克是
- Emoji表情符号录入MySQL数据库报错的解决方案