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. 如何设置httpd-mpm-conf的参数

    原文链接:http://blog.sina.com.cn/s/blog_626998030102wohs.html 首先确定apache是使用哪种工作模式是prefork模式还是worker模式查看方 ...

  2. postgresql逻辑结构--用户及权限管理(七)

    一.用户和角色 二.创建用户和角色 三.权限管理 四.

  3. [Python] 震惊, 我居然用Python干这种事ꈍ .̮ ꈍ

    阅读本文只需花费你两分钟, 两分钟你买不了吃亏,你也买不了上当. 那么, 为何不静下心来看看呢? Python 海龟创意绘画, Turtle库创作精美图画 Author:Amd794     E-ma ...

  4. 第六章 对象作用域与servlet事件监听器

          作用域对象 Servlet上下文监听器 Servlet会话监听器 Servlet请求监听器     一:对象作用域 作用域对象 属性操作方法 作用域范围说明 ServletContext( ...

  5. Spring-Task思维导图

    最近在搞一个定时任务的相关东西,为了方便记忆,这里将知识点总结成一个思维导图.后续也会通过思维导图的方式发布博客.

  6. ConcurrentHashMap 源码阅读小结

    前言 每一次总结都意味着重新开始,同时也是为了更好的开始.ConcurrentHashMap 一直是我心中的痛.虽然不敢说完全读懂了,但也看了几个重要的方法,有不少我觉得比较重要的知识点. 然后呢,放 ...

  7. css中添加屏幕自适应方法(rem)

    css中添加屏幕自适应方法(rem) 只需要在公共css文件中添加下面代码:设计稿以750px,基础字体为20px为例,兼容性高,使用过程中px转化为rem即可 /*竖屏*/ @media scree ...

  8. C#中HttpWebRequest的用法详解

    原文链接:http://www.cnblogs.com/love201314/p/5029312.html 1.HttpWebRequest和HttpWebResponse类是用于发送和接收HTTP数 ...

  9. 第16课-数据库开发及ado.net-数据库SQl,创建数据库和表,增删改语句,约束,top和Distinct,聚合函数介绍

    第16课-数据库开发及ado.net 数据库SQl,创建数据库和表,增删改语句,约束,top和Distinct,聚合函数介绍 SQL语句入门(脚本.命令) SQL全名是结构化查询语言(Structur ...

  10. [PHP] 看博客学习插入排序

    定义数组长度变量$len,使用count()函数,参数:数组 for循环数组,条件:从第二个开始,遍历数组,循环内 定义临时变量$temp,赋值当前元素 for循环数组,条件:遍历当前元素前面的所有元 ...