lintcode-二叉树的中序遍历(非递归)-67
来源:互联网 发布:java bio nio aio详解 编辑:程序博客网 时间:2024/06/04 18:08
给出一棵二叉树,返回其中序遍历
您在真实的面试中是否遇到过这个题?Yes
样例
给出二叉树 {1,#,2,3}
,
1 \ 2 / 3
返回 [1,3,2]
/** * Definition of TreeNode: * class TreeNode { * public: * int val; * TreeNode *left, *right; * TreeNode(int val) { * this->val = val; * this->left = this->right = NULL; * } * } */class Solution { public: vector<int> inorderTraversal(TreeNode *root) { stack<TreeNode*> s; TreeNode *cur=root; vector<int> ret; while(cur||!s.empty()){ if(cur){ s.push(cur); cur=cur->left; }else{ cur=s.top(); ret.push_back(cur->val); s.pop(); cur=cur->right; } } return ret; }};
0 0
- lintcode-二叉树的中序遍历(非递归)-67
- 【LintCode-67】二叉树的中序遍历(Java实现-递归算法/非递归算法)
- 二叉树的中序遍历(lintcode)(递归和非递归)
- Lintcode 二叉树的中序遍历(递归+非递归)
- lintcode-二叉树的前序遍历(非递归)-66
- LintCode Binary Tree Inorder Traversal 二叉树的中序遍历(非递归)
- 二叉树后续非递归遍历-lintcode
- LintCode 二叉树的遍历 (非递归)
- Lintcode 二叉树的前序遍历 (递归和非递归法)
- 【LintCode-66】二叉树的前序遍历(Java实现-递归算法/非递归算法)
- 二叉树的中序递归,非递归遍历
- 二叉树前、中、后序遍历【非递归】【LintCode测试平台】
- LintCode Binary Tree Preorder Traversal二叉树的前序遍历(非递归)
- 二叉树非递归后序遍历(非递归遍历中最麻烦的一个)
- 【二叉树遍历】中序------非递归
- 非递归中序遍历二叉树
- 中序遍历二叉树 [非递归]
- 非递归中序遍历二叉树
- 正则表达式基本语法
- 单词切分
- maven目录结构
- java学习之正则表达式
- 博客的利弊浅析
- lintcode-二叉树的中序遍历(非递归)-67
- iOS第三方推送(信鸽)
- C++Primer第五版 5.3.1节练习
- LuckyDial抽奖转盘
- event.logtags
- HDU 1081 To The Max
- Windows Socket 编程_ 简单的服务器/客户端程序
- UVa 12569:Planning mobile robot on Tree(EASY Version)(BFS)
- python_docx