Lintcode67 Binary Tree Inorder Traversal solution 题解
来源:互联网 发布:android 仿照淘宝排序 编辑:程序博客网 时间:2024/06/07 13:52
【题目描述】
Given a binary tree, return the inorder traversal of its nodes' values.
给出一棵二叉树,返回其中序遍历
【题目链接】
www.lintcode.com/en/problem/binary-tree-inorder-traversal/
【题目解析】
递归版
最好理解,递归调用时注意返回值和递归左右子树的顺序即可。
迭代版
使用辅助栈,空间复杂度O(n),时间复杂度O(n).
中序遍历没有前序遍历好写,其中之一就在于入栈出栈的顺序和限制规则。我们采用「左根右」的访问顺序可知主要有如下四步构成。
1.首先需要一直对左子树迭代并将非空节点入栈
2.节点指针为空后不再入栈
3.当前节点为空时进行出栈操作,并访问栈顶节点
4.将当前指针p用其右子节点替代
步骤2,3,4对应「左根右」的遍历结构,只是此时的步骤2取的左值为空。
【参考答案】
www.jiuzhang.com/solutions/binary-tree-inorder-traversal/
阅读全文
0 0
- Lintcode67 Binary Tree Inorder Traversal solution 题解
- Lintcode67 Binary Tree Inorder Traversal solution 题解
- Binary Tree Inorder Traversal题解
- 题解:Binary Tree Inorder Traversal
- [LeetCode] Binary Tree Inorder Traversal Solution
- Lintcode72 Construct Binary Tree from Inorder and Postorder Traversal solution 题解
- Lintcode73 Construct Binary Tree from Preorder and Inorder Traversal solution 题解
- Lintcode72 Construct Binary Tree from Inorder and Postorder Traversal solution 题解
- Lintcode73 Construct Binary Tree from Preorder and Inorder Traversal solution 题解
- LeetCode题解:Binary Tree Inorder Traversal
- LeetCode题解:Binary Tree Inorder Traversal
- leetcode题解-94. Binary Tree Inorder Traversal
- LeetCode 94. Binary Tree Inorder Traversal 题解
- Lintcode66 Binary Tree Preorder Traversal solution 题解
- Lintcode68 Binary Tree Postorder Traversal solution 题解
- Lintcode68 Binary Tree Postorder Traversal solution 题解
- [LeetCode] Construct Binary Tree from Preorder and Inorder Traversal, Solution
- LeetCode 94. Binary Tree Inorder Traversal java solution
- 文章标题
- 把一个Array数组拷贝到另一个Array数组
- 用Python从零开始实现一个Bloomfilter
- Mac安装zookeeper伪集群
- 一元线性回归,多元线性回归,MATLAB
- Lintcode67 Binary Tree Inorder Traversal solution 题解
- 判断是否属于同一子网
- 优化问题中的对偶性理论
- linux 内核配置、编译、
- 序列化和反序列化
- Spark2.0.X源码深度剖析之 Spark Submit..
- 实例探索Java模式之路——适配器模式
- C语言之typedef详解
- Lintcode68 Binary Tree Postorder Traversal solution 题解