原题地址

基本二叉树操作。

O[       ][              ]

[       ]O[              ]

代码:

 TreeNode *restore(vector<int> &preorder, vector<int> &inorder, int pp, int ip, int len) {
if (len <= )
return NULL; TreeNode *node = new TreeNode(preorder[pp]); if (len == )
return node; int leftLen = ;
while (inorder[ip + leftLen] != preorder[pp])
leftLen++;
node->left = restore(preorder, inorder, pp + , ip, leftLen);
node->right = restore(preorder, inorder, pp + leftLen + , ip + leftLen + , len - leftLen - ); return node;
} TreeNode *buildTree(vector<int> &preorder, vector<int> &inorder) {
return restore(preorder, inorder, , , preorder.size());
}

Leetcode#105 Construct Binary Tree from Preorder and Inorder Traversal的更多相关文章

  1. [LeetCode] 105. Construct Binary Tree from Preorder and Inorder Traversal 由先序和中序遍历建立二叉树

    Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  2. (二叉树 递归) leetcode 105. Construct Binary Tree from Preorder and Inorder Traversal

    Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  3. LeetCode 105. Construct Binary Tree from Preorder and Inorder Traversal (用先序和中序树遍历来建立二叉树)

    Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  4. leetcode 105 Construct Binary Tree from Preorder and Inorder Traversal ----- java

    Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  5. LeetCode 105. Construct Binary Tree from Preorder and Inorder Traversal 由前序和中序遍历建立二叉树 C++

    Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  6. Java for LeetCode 105 Construct Binary Tree from Preorder and Inorder Traversal

    Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that ...

  7. [leetcode] 105. Construct Binary Tree from Preorder and Inorder Traversal (Medium)

    原题 题意: 根据先序和中序得到二叉树(假设无重复数字) 思路: 先手写一次转换过程,得到思路. 即从先序中遍历每个元素,(创建一个全局索引,指向当前遍历到的元素)在中序中找到该元素作为当前的root ...

  8. leetcode 105. Construct Binary Tree from Preorder and Inorder Traversal,剑指offer 6 重建二叉树

    不用迭代器的代码 class Solution { public: TreeNode* reConstructBinaryTree(vector<int> pre,vector<in ...

  9. 【LeetCode】105. Construct Binary Tree from Preorder and Inorder Traversal

    Construct Binary Tree from Preorder and Inorder Traversal Given preorder and inorder traversal of a ...

随机推荐

  1. JS获取网页属性包括宽、高等

    JS获取网页属性包括宽.高等. function getInfo()  { // www.jbxue.com var s = "";  s += " 网页可见区域宽:&q ...

  2. Windows下安装redis,并与PHP使用

    一.在windows下安装redis: redis的官方网站下载地址:http://redis.io/download 进入以上网址之后,请见以下的图片操作下载redis: 第一步: 第二步:在对应的 ...

  3. DevExpress 中 在做全选的全消功能的时候 加快效率

    在做 DevExpress 中对增加的选择 Check列 控制全选的全消时通过以下代码红色字代码效率会有明显的提升: private void CheckedRow() { try { splashS ...

  4. 基于OWIN WebAPI

    http://www.cnblogs.com/Irving/p/4607104.html http://www.cnblogs.com/xishuai/p/aspnet-webapi-owin-oau ...

  5. 关于js中this的疑问

    学习bootstrap.js源码中被js里边的this绕的有点晕 /* ================================================================ ...

  6. IT新人论成长

    说自己是新人,其实自己也不新了,2012年毕业,辗转3个城市,现在在上海一家公司,工资不到5K. 在来现在公司之前,我从事web后台开发,采用MVC模式,虽然做了不少的网站,但感觉自己的水平还是在底层 ...

  7. 第六章 管理类型(In .net4.5) 之 创建类型

    1. 概述 本章内容包括 C#5中如何更好的创建类型以及如何扩展现有类型. 2. 主要内容 2.1 如何选择类型 C#类型系统包括三种类型:值类型.引用类型.指针类型.(指针类型用于非托管代码,很少使 ...

  8. Oracle Study Note : Tablespace and Data Files

    1.how to create a tablespace that employs the most common features create tablespace tb_name #create ...

  9. 1084. Broken Keyboard (20)

    On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters ...

  10. Mybatis 中常用的java类型与jdbc类型

    JDBC Type Java Type CHAR String VARCHAR String LONGVARCHAR String NUMERIC java.math.BigDecimal DECIM ...