LeetCode题解之 Increasing Order Search Tree
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的更多相关文章
- 【LeetCode】897. Increasing Order Search Tree 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 重建二叉树 数组保存节点 中序遍历时修改指针 参考资 ...
- 【leetcode】897. Increasing Order Search Tree
题目如下: 解题思路:我的方法是先用递归的方法找出最左边的节点,接下来再对树做一次递归中序遍历,找到最左边节点后将其设为root,其余节点依次插入即可. 代码如下: # Definition for ...
- LeetCode 897. 递增顺序查找树(Increasing Order Search Tree)
897. 递增顺序查找树 897. Increasing Order Search Tree 题目描述 给定一个树,按中序遍历重新排列树,使树中最左边的结点现在是树的根,并且每个结点没有左子结点,只有 ...
- 【Leetcode_easy】897. Increasing Order Search Tree
problem 897. Increasing Order Search Tree 参考 1. Leetcode_easy_897. Increasing Order Search Tree; 完
- 897. Increasing Order Search Tree
题目来源: https://leetcode.com/problems/increasing-order-search-tree/ 自我感觉难度/真实难度:medium/easy 题意: 分析: 自己 ...
- 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 ...
- [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 ...
- [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 ...
- LeetCode.897-递增搜索树(Increasing Order Search Tree)
这是悦乐书的第346次更新,第370篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第211题(顺位题号是897).给定一棵树,按中序遍历顺序重新排列树,以便树中最左边的节 ...
随机推荐
- Mybatis 事务管理和缓存机制
一级缓存--SqlSession级别 数据库表tb_user User package com.example.demo.domain; public class User { private Int ...
- 03-01:springboot 整合jsp
1.修改pom文件,添加坐标 <!-- jstl --> <dependency> <groupId>javax.servlet ...
- JavaScript -- Form
-----048-Form.html----- <!DOCTYPE html> <html> <head> <meta http-equiv="co ...
- linux-centos使用 wget命令获取jdk
1, 首先去官网看下地址是否变化了 2, 然后输入以下命令即可 wget --no-check-certificate --no-cookies --header "Cookie: orac ...
- smarty安装与配置
smarty是一个 PHP 模板引擎,也就是一个类库, 可以到官网下载,也可以到其GitHub地址去下载: 鄙人下载的是 3.1.32版本,解压后的目录结构如下: 最重要的是 libs 目录,demo ...
- 揭开Future的神秘面纱——任务执行
前言 此文承接之前的博文 解开Future的神秘面纱之取消任务 补充一些任务执行的一些细节,并从全局介绍程序的运行情况. 系列目录 揭开Future的神秘面纱——任务取消 揭开Future的神秘面纱— ...
- let‘s encrypt之nginx-https没有小锁
1.使用let's encrypt 加密后的nginx,访问的时候,发现没有小锁,chrome中: 火狐浏览器上: 会看到如上信息,这是因为css.图片或javascript任然通过http提供,可以 ...
- Java 使用gson 解析 Json
json数据 { "resultcode": "200", "reason": "successed!", " ...
- ASP.NET编辑与更新数据(非GridView控件实现)
Insus.NET在实现<ASP.NET开发,从二层至三层,至面向对象 (5)>http://www.cnblogs.com/insus/p/3880606.html 中,没有把数据编辑与 ...
- 使用cglib实现数据库框架的级联查询
写在前面的 这一章是之前写的<手把手教你写一个Java的orm框架> 的追加内容.因为之前写的数据库框架不支持级联查询这个操作,对于有关联关系的表用起来还是比较麻烦,于是就准备把这个功能给 ...