leetcode Binary Tree Inorder Traversal
2014-08-21 21:40
295 查看
非递归,则利用栈来保存父节点的信息
代码
代码
class Solution { public: vector<int> inorderTraversal(TreeNode *root) { vector<int> result; stack<TreeNode *> nodeStack; if(root==NULL) return result; TreeNode *p = root; while(!nodeStack.empty()||p) { if(p) { nodeStack.push(p); p = p->left; } else { TreeNode *temp = nodeStack.top(); result.push_back(temp->val); nodeStack.pop(); p = temp->right; } } return result; } };
相关文章推荐
- LeetCode Online Judge 题目C# 练习 - Binary Tree Inorder Traversal
- 【LeetCode with Python】 Binary Tree Inorder Traversal
- Leetcode: Construct Binary Tree from Preorder and Inorder Traversal
- LeetCode: Binary Tree Inorder Traversal
- [Leetcode] Construct Binary Tree from Preorder and Inorder Traversal
- LeetCode Construct Binary Tree from Preorder and Inorder Traversal
- LeetCode: Construct Binary Tree from Inorder and Postorder Traversal
- [LeetCode]Construct Binary Tree from Inorder and Postorder Traversal
- [LeetCode] Construct Binary Tree from Preorder and Inorder Traversal
- leetcode 63: Binary Tree Inorder Traversal
- [leetcode]Construct Binary Tree from Preorder and Inorder Traversal
- LeetCode Construct Binary Tree from Inorder and Postorder Traversal
- LeetCode : Binary Tree Inorder Traversal
- [LeetCode]Construct Binary Tree from Preorder and Inorder Traversal
- LeetCode: Construct Binary Tree from Preorder and Inorder Traversal
- [Leetcode] Binary Tree Inorder Traversal
- Leetcode: Binary Tree Inorder Traversal
- [LeetCode] Construct Binary Tree from Inorder and Postorder Traversal
- [LeetCode] Construct Binary Tree from Preorder and Inorder Traversal, Solution
- LeetCode Binary Tree Inorder Traversal