Leetcode: Binary Tree Inorder Traversal
2013-01-07 11:57
344 查看
//the key is to use a stack smartly class Solution { public: vector<int> inorderTraversal(TreeNode *root) { // Start typing your C/C++ solution below // DO NOT write int main() function //if(root==NULL) //return NULL; stack<TreeNode*> s; vector<int> v; v.clear(); TreeNode* np=root; while(1){ while(np){ s.push(np); np=np->left; } if(s.empty()) break; TreeNode* tmp=s.top(); s.pop(); v.push_back(tmp->val); np=tmp->right; } return v; }
相关文章推荐
- [LeetCode]Construct Binary Tree from Preorder and Inorder Traversal
- Leetcode 105. Construct Binary Tree from Preorder and Inorder Traversal (Medium) (cpp)
- LeetCode 105. Construct Binary Tree from Preorder and Inorder Traversal
- 【Leetcode】【Medium】Construct Binary Tree from Preorder and Inorder Traversal
- LeetCode:Binary Tree Inorder Traversal
- 【leetcode】Construct Binary Tree from Preorder and Inorder Traversal
- LeetCode - 106. Construct Binary Tree from Inorder and Postorder Traversal
- 【LeetCode】Binary Tree Inorder Traversal
- [leetcode] Construct Binary Tree from Preorder and Inorder Traversal
- leetcode - Binary Tree Inorder Traversal
- LeetCode 105 Construct Binary Tree from Preorder and Inorder Traversal
- LeetCode106 Construct Binary Tree from Inorder and Postorder Traversal
- [Leetcode][JAVA] Binary Tree Preorder Traversal, Binary Tree Inorder Traversal, Binary Tree Postorder Traversal
- leetcode Construct Binary Tree from Inorder and Postorder Traversal 难度系数3 3.38
- LeetCode 105. Construct Binary Tree from Preorder and Inorder Traversal
- [LeetCode] Binary Tree Inorder Traversal
- 【leetcode】【94】Binary Tree Inorder Traversal
- LeetCode题解:Construct Binary Tree from Inorder and Postorder Traversal
- LeetCode | Construct Binary Tree from Preorder and Inorder Traversal
- leetcode Construct Binary Tree from Inorder and Postorder Traversal