This is a fundamental and yet classic problem. I share my three solutions here:Iterative solution using stack ---O(n)time andO(n)space;Recursive solut...
分类:
其他好文 时间:
2015-06-03 00:49:25
阅读次数:
132
Given inorder and postorder traversal of a tree, construct the binary tree.
给定一个二叉树的后序和中序遍历,重建这棵二叉树。
此题和LeetCode105 根据前序和中序重建二叉树类似。
所谓后序遍历,即先访问根的左、右子树,然后再访问根节点。这样根节点在二叉树后序遍历的最后一个个元素。
所谓中序遍...
分类:
其他好文 时间:
2015-06-01 22:48:13
阅读次数:
126
Given a binary tree, return the inorder traversal of its nodes’ values.For example:
Given binary tree {1,#,2,3},1
\
2
/
3return [1,3,2].
题目要求对二叉树进行非递归的中序遍历,所谓前序遍历即,先访问左子树、再访问根节点、然...
分类:
其他好文 时间:
2015-06-01 22:47:56
阅读次数:
137
Binary Tree Preorder Traversal:https://leetcode.com/problems/binary-tree-preorder-traversal/
Binary Tree Inorder Traversal :https://leetcode.com/problems/binary-tree-inorder-traversal/
Binary Tree Po...
分类:
其他好文 时间:
2015-06-01 22:45:30
阅读次数:
137
本文主要对binary tree和tree相关问题做一个review,然后一道一道解决leetcode中的相关问题。因为是review了,所以基本概念定义什么的就不赘述。review主要包括:inorder, postorder,preorder traversal的iterative versio...
分类:
其他好文 时间:
2015-05-28 07:04:49
阅读次数:
120
利用一棵二叉树的中序遍历的结果数组和后续遍历的结果数组复原该树:采用分治策略,解析如下图:如图:中序遍历数组的division特征为左(0 --> x) 根(x + 1) 右(x + 2 --> length - 1) 后序遍历数组的division特征为左(0 --> x) 根(x + 1 ...
分类:
其他好文 时间:
2015-05-27 11:46:53
阅读次数:
125
二叉查找树性质设x是二叉查找树中的一个结点,如果y是x的左子树中的一个结点,则k[y]=k[x]1 //中序遍历算法,输出二叉查找树T中的全部元素2 INORDER-TREE-WALK(x)3 if x!=nil4 then INORDER-TREE-WALK(left[x])5 ...
分类:
编程语言 时间:
2015-05-26 22:59:04
阅读次数:
114
Construct Binary Tree from Inorder and Postorder TraversalTotal Accepted: 31041 Total Submissions: 115870Given inorder and postorder traversal of a tr...
分类:
编程语言 时间:
2015-05-23 19:56:06
阅读次数:
159
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.解题思路一:preorder[...
分类:
编程语言 时间:
2015-05-23 11:11:46
阅读次数:
129
Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].Note...
分类:
其他好文 时间:
2015-05-22 09:22:37
阅读次数:
110