leetcode:Binary Tree Postorder Traversal
来源:互联网 发布:au软件怎么用 编辑:程序博客网 时间:2024/06/06 10:04
/** * 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) { stack<int> statusStack; stack<TreeNode *> traversalStack; vector<int> result; if(root == NULL) return result; statusStack.push(0); traversalStack.push(root); while(false == traversalStack.empty()) { TreeNode * currentNode = traversalStack.top(); traversalStack.pop(); int currentStatus = statusStack.top(); statusStack.pop(); if(currentStatus == 1) { result.push_back(currentNode->val); } else { statusStack.push(1); traversalStack.push(currentNode); if(currentNode->right != NULL) { statusStack.push(0); traversalStack.push(currentNode->right); } if(currentNode->left != NULL) { statusStack.push(0); traversalStack.push(currentNode->left); } } } return result; }};
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
- 第12周 项目3-2 奇数的奇数阶乘
- 树目录
- ExtJS001
- socket异常及原因分析
- 《精通Linux设备驱动程序开发》——PCI
- leetcode:Binary Tree Postorder Traversal
- 一个简单的Php服务端
- spring tool suite juno 创建spring mvc 项目及遇到无法把maven依赖jar包发布到服务器下解决
- 《高效的贝塞尔曲线》-示例
- iis 更新apk 报错404.3
- CDateTimeCtrl 用法总结
- 第十二周项目1-4:理解函数的默认从拿书·默认参数
- Linux常用命令(二十一) - find之参数详解
- MFC中的坐标