1、题目描述

2/问题分析

利用中序遍历,然后重新构造树。

3、代码

 TreeNode* increasingBST(TreeNode* root) {
if (root == NULL)
return NULL;
vector<int> v;
inorder(root,v); TreeNode* dummy = new TreeNode();
TreeNode *p = dummy;
for (vector<int>::iterator it = v.begin(); it != v.end(); it++) {
TreeNode *tmp = new TreeNode(*it);
p->right = tmp;
p = p->right;
} return dummy->right;
} void inorder(TreeNode *root, vector<int> &v)
{
if (root == NULL)
return ;
inorder(root->left, v);
v.push_back(root->val);
inorder(root->right,v);
}

LeetCode题解之 Increasing Order Search Tree的更多相关文章

  1. 【LeetCode】897. Increasing Order Search Tree 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 重建二叉树 数组保存节点 中序遍历时修改指针 参考资 ...

  2. 【leetcode】897. Increasing Order Search Tree

    题目如下: 解题思路:我的方法是先用递归的方法找出最左边的节点,接下来再对树做一次递归中序遍历,找到最左边节点后将其设为root,其余节点依次插入即可. 代码如下: # Definition for ...

  3. LeetCode 897. 递增顺序查找树(Increasing Order Search Tree)

    897. 递增顺序查找树 897. Increasing Order Search Tree 题目描述 给定一个树,按中序遍历重新排列树,使树中最左边的结点现在是树的根,并且每个结点没有左子结点,只有 ...

  4. 【Leetcode_easy】897. Increasing Order Search Tree

    problem 897. Increasing Order Search Tree 参考 1. Leetcode_easy_897. Increasing Order Search Tree; 完

  5. 897. Increasing Order Search Tree

    题目来源: https://leetcode.com/problems/increasing-order-search-tree/ 自我感觉难度/真实难度:medium/easy 题意: 分析: 自己 ...

  6. LeetCode 897 Increasing Order Search Tree 解题报告

    题目要求 Given a tree, rearrange the tree in in-order so that the leftmost node in the tree is now the r ...

  7. [LeetCode] 897. Increasing Order Search Tree 递增顺序查找树

    Given a tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root o ...

  8. [LeetCode&Python] Problem 897. Increasing Order Search Tree

    Given a tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root o ...

  9. LeetCode.897-递增搜索树(Increasing Order Search Tree)

    这是悦乐书的第346次更新,第370篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第211题(顺位题号是897).给定一棵树,按中序遍历顺序重新排列树,以便树中最左边的节 ...

随机推荐

  1. js去除字符串中的标签

    var str="<p>js去除字符串中的标签</p>"; var result=str.replace(/<.*?>/ig,"&qu ...

  2. WebLogic 12c Linux 命令行 安装

    最近负责在Linux上安装WebLogic Server 12c,客户说要安装最新的版本,版本号为 12.1.X(12.1.2,12.1.3).开始以为和旧版安装一样,使用控制台的方式,下载bin文件 ...

  3. js写的一个简单的手风琴菜单

    1 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&q ...

  4. 如何从GitHub迁移到GitLab?

    如何从GitHub迁移到GitLab? 在本文中,我们将解释如何从Github迁移到Gitlab,同时我们也将解释如何将Github的开源项目导入到Gitlab. 正如你可能非常清楚的那样, Gitl ...

  5. [转]Webpack 入门教程

    本文转自:http://www.runoob.com/w3cnote/webpack-tutorial.html Webpack 是一个前端资源加载/打包工具.它将根据模块的依赖关系进行静态分析,然后 ...

  6. Spring Security认证配置(二)

    学习本章之前,可以先了解下上篇Spring Security基本配置. 本篇想要达到这样几个目的: 1.访问调用者服务时,如果是html请求,则跳转到登录页,否则返回401状态码和错误信息 2.调用方 ...

  7. c#里面如何激活一个外部程序进程并显示在最前

    using System.Diagnostics; using System.Runtime.InteropServices; [DllImport("user32.dll")] ...

  8. 浅谈Http协议是怎么回事?

    老实说关于http协议这个概念,见到最多的还是各类招聘信息.在平时的工作中,除了了解一些请求,响应,请求头这些概念外,对于http协议也没有太多的关心.因为貌似对平时的工作没有什么影响,所以在写这篇关 ...

  9. Lucene 学习-安装 Kibana 视图界面

    Kibana 是一个开源的分析与可视化平台,设计出来用于和 Elasticsearch 一起使用的. 你可以使用 Kibana 搜索.查看.交互存放在 Elasticsearch 索引里的数据.使用各 ...

  10. The area (hdu1071)积分求面积

    The area Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...