Two elements of a binary search tree (BST) are swapped by mistake.

Recover the tree without changing its structure.

Example 1:

Input: [1,3,null,null,2]

   1
/
3
\
2 Output: [3,1,null,null,2] 3
/
1
\
2

Example 2:

Input: [3,1,4,null,null,2]

  3
/ \
1 4
/
2 Output: [2,1,4,null,null,3] 2
/ \
1 4
/
3

Follow up:

  • A solution using O(n) space is pretty straight forward.
  • Could you devise a constant space solution?

题意:

二叉搜索树中的两个节点被调换了,麻烦给调回来。

[leetcode]99. Recover Binary Search Tree恢复二叉搜索树的更多相关文章

  1. [LeetCode] 99. Recover Binary Search Tree 复原二叉搜索树

    Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...

  2. [Leetcode] Recover binary search tree 恢复二叉搜索树

    Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...

  3. [LeetCode] Recover Binary Search Tree 复原二叉搜索树

    Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...

  4. [LeetCode] 98. Validate Binary Search Tree 验证二叉搜索树

    Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as ...

  5. [leetcode]98. Validate Binary Search Tree验证二叉搜索树

    Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as ...

  6. 099 Recover Binary Search Tree 复原二叉搜索树

    二叉排序树中有两个节点被交换了,要求把树恢复成二叉排序树. 详见:https://leetcode.com/problems/recover-binary-search-tree/submission ...

  7. [CareerCup] 4.5 Validate Binary Search Tree 验证二叉搜索树

    4.5 Implement a function to check if a binary tree is a binary search tree. LeetCode上的原题,请参见我之前的博客Va ...

  8. [LeetCode] 99. Recover Binary Search Tree(复原BST) ☆☆☆☆☆

    Recover Binary Search Tree leetcode java https://leetcode.com/problems/recover-binary-search-tree/di ...

  9. leetcode 99 Recover Binary Search Tree ----- java

    Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...

随机推荐

  1. rsync的daemon模式

    官方文档:https://download.samba.org/pub/rsync/rsyncd.conf.html   1:daemon模式配置文件         rsync以daemon方式运行 ...

  2. webpack 中,module、chunk、bundle 的区别(待补充)

    项目 区别 module 是开发中的单个模块 chunk 中文意思是"块",是指 webpack 在进行模块依赖分析的时候,代码分割出来的代码块 bundle

  3. Linux cp命令详解

    Linux cp命令 Linux cp命令主要用于复制文件或目录,将源文件复制至目标文件,或将多个源文件复制至目标目录 用法: cp [选项]... [-T] 源文件 目标文件 cp [选项]... ...

  4. CentOS 7.2 下nginx SSL证书部署的方法(使用crt以及key 配置)

    转自:https://www.jb51.net/article/107350.htm 环境 系统环境:CentOS6.7 nginx version: nginx/1.8.1 证书 ? 1 2 3 # ...

  5. 【算法和数据结构】_15_小算法_打印EOF的值

    /* 本程序打印EOF的值 */ #include <stdio.h> int main(int argc,char* argv[],char* env) { printf("E ...

  6. 用TreeSet和Comparator给list集合元素去重

    今天在做导入功能时,看到一个感觉很好的去重算法,特分享给大家看看: 其原理利用了以下几点: 1.TreeSet里面不会有重复的元素,所以当把一个List放进TreeSet里面后,会自动去重 2.Tre ...

  7. Ubuntu 16.04 安装 JDK 1.8

    系统环境 Ubuntu 16.04; JDK 1.8 配置安装 1.首先从oracle下载jdk 1.8,我下载的版本是jdk-8u131-linux-x64.tar.gz,运行tar zvxf jd ...

  8. 实战ELK(5) Logstash 入门

    Logstash 是一个开源的数据收集引擎,它具有备实时数据传输能力.它可以统一过滤来自不同源的数据,并按照开发者的制定的规范输出到目的地. 一.原理 Logstash 通过管道进行运作,管道有两个必 ...

  9. MySQL - 用户变量

    MySQL用户变量:基于会话变量实现的,可以暂存值,并传递给同一连接里的下一条sql使用的变量,当客户端连接退出时,变量会被释放. MySQL用户变量应用场景:同一连接,未关闭情况下,帮你暂存一些计算 ...

  10. oracle 11g密码过期问题解决方法

    ORACLE 11G密码过期问题: 1.使用oracle用户进入sql编辑器中执行修改密码(原始密码,保持不变)的命令 sql>alter user 用户名 identified by &quo ...