Given a binary tree, return the inorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
1
2
/
3
return [1,3,2].
Note: Recursive solutio...
分类:
其他好文 时间:
2014-08-16 11:15:00
阅读次数:
227
火车进站,模拟一个栈的操作,额外的栈操作,查看是否能按照规定顺序出栈。
数据量很少,故此题目很容易AC。
直接使用数组模拟就好。
#include
const int MAX_N = 10;
char inOrder[MAX_N], outOrder[MAX_N], stk[MAX_N];
bool rs[MA...
分类:
其他好文 时间:
2014-08-12 03:27:23
阅读次数:
232
思路:先序的第一个元素和后序的最后一个元素是当前子树的根,然后遍历中序序列,找到左右子树的分界线,递归建左子树和右子树。
class Solution {
public:
/*由于是oj,这里假设给的序列是合法的,正常情况是需要判断不合法情况的 */
TreeNode *buildTree(vector &inorder, vector &postorder,int instar...
分类:
其他好文 时间:
2014-08-11 21:37:42
阅读次数:
504
Given inorder and postorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
给出二叉树的中序遍历和后序遍历结果,恢复出二叉树。
后序遍历序列的最后一个元素值是二叉树的根节点的值,查找...
分类:
其他好文 时间:
2014-08-09 23:15:09
阅读次数:
312
Given preorder and inorder traversal of a tree, construct the binary tree.Note: You may assume that duplicates do not exist in the tree./** * Definiti...
分类:
其他好文 时间:
2014-08-05 00:01:38
阅读次数:
271
Given inorder and postorder traversal of a tree, construct the binary tree.Note: You may assume that duplicates do not exist in the tree.class Solutio...
分类:
其他好文 时间:
2014-08-04 23:57:18
阅读次数:
476
问题:二叉树中序遍历递归实现/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) :...
分类:
其他好文 时间:
2014-08-02 12:40:33
阅读次数:
162
Given inorder and postorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
/**
* Definition for binary tree
* struct TreeNode {...
分类:
其他好文 时间:
2014-08-01 19:53:32
阅读次数:
222
题目:Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.题解:这道题跟pre....
分类:
编程语言 时间:
2014-08-01 06:56:51
阅读次数:
185
题目:Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.题解: 1 ...
分类:
编程语言 时间:
2014-08-01 06:56:41
阅读次数:
228