根据BST的特点,如果小于L就判断右子树,如果大于R就判断左子树

递归地建立树

public TreeNode trimBST(TreeNode root, int L, int R) {
if (root==null) return null;
if (root.val<L) return trimBST(root.right,L,R);
if (root.val>R) return trimBST(root.left,L,R);
TreeNode res = new TreeNode(root.val);
res.left = trimBST(root.left,L,R);
res.right = trimBST(root.right,L,R);
return res;
}

[leetcode]669. Trim a Binary Search Tree寻找范围内的二叉搜索树的更多相关文章

  1. LeetCode: 669 Trim a Binary Search Tree(easy)

    题目: Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so th ...

  2. LeetCode 669 Trim a Binary Search Tree 解题报告

    题目要求 Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so t ...

  3. [Leetcode]669 Trim a Binary Search Tree

    Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that a ...

  4. LeetCode 669. Trim a Binary Search Tree修剪二叉搜索树 (C++)

    题目: Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so th ...

  5. [LeetCode] Convert Sorted List to Binary Search Tree 将有序链表转为二叉搜索树

    Given a singly linked list where elements are sorted in ascending order, convert it to a height bala ...

  6. [LeetCode] Convert Sorted Array to Binary Search Tree 将有序数组转为二叉搜索树

    Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 这道 ...

  7. [LeetCode] 272. Closest Binary Search Tree Value II 最近的二叉搜索树的值 II

    Given a non-empty binary search tree and a target value, find k values in the BST that are closest t ...

  8. PAT A1099 Build A Binary Search Tree (30 分)——二叉搜索树,中序遍历,层序遍历

    A Binary Search Tree (BST) is recursively defined as a binary tree which has the following propertie ...

  9. Convert Sorted List to Binary Search Tree——将链表转换为平衡二叉搜索树 &&convert-sorted-array-to-binary-search-tree——将数列转换为bst

    Convert Sorted List to Binary Search Tree Given a singly linked list where elements are sorted in as ...

随机推荐

  1. XOR性质

    异或XOR的性质: 1. 交换律 2. 结合律 3. x^x = 0 -> 偶数个异或为0 4. x^0 = x -> 奇数个异或为本身 5. 自反性:a^b^b = a^0 =a

  2. 05_Content Provider

    Content Provider是内容提供器,与内容(数据)的存取(存储.获取)有关,是Android应用程序的四大组成部分之一,是Android中的跨应用访问数据机制. 数据库在Android当中是 ...

  3. win10下安装anaconda3+tensorflow

    安装了三天终于安装成功了,今天简单写下自己的安装步骤 1.下载可以在Anaconda3官网下载:https://www.anaconda.com/products/individual 也可以通过清华 ...

  4. 【2020.11.28提高组模拟】T1染色(color)

    [2020.11.28提高组模拟]T1染色(color) 题目 题目描述 给定 \(n\),你现在需要给整数 \(1\) 到 \(n\) 进行染色,使得对于所有的 \(1\leq i<j\leq ...

  5. 七. Vue Router详解

    1. 认识路由 1.1 路由概念 路由是什么? 路由是一个网络工程里面的术语. 路由(routing)就是通过互联的网络把信息从源地址传输到目的地址的活动 --- 维基百科 路由器提供了两种机制:路由 ...

  6. PyQt(Python+Qt)学习随笔:Qt Designer中部件的windowTitle和windowOpacity属性

    windowOpacity 这个属性仅对window对象生效. windowOpacity为浮点数,表示透明度,为1完全不透明,为0完全透明,缺省是1. 可以通过windowOpacity().set ...

  7. 从HBase底层原理解析HBASE列族不能设计太多的原因?

    在之前的文章<深入探讨HBASE>中,笔者详细介绍了: HBase基础知识(包括简介.表结构).系统架构.数据存储 WAL log和HBase中LSM树的应用 HBase寻址机制 mino ...

  8. AcWing 309. 装饰围栏

    题目链接 这道题与下一章的数位\(dp\)解题思路十分一致. 把寻找答案变成按位(并且是字典序从小到大)枚举当前这一位可以填的情况. 通过\(dp\)预处理的信息告诉我们可行性,就可以把答案紧逼到一个 ...

  9. 第一章、Docker 简介

    笔记内容来自:第一本Docker书 [澳] James Turnbull 著 李兆海 刘斌 巨震 ​ Docker 是一个能够把开发的应用程序自动部署到容器的开源引擎.(由Docker 公司,前dot ...

  10. STL——容器(List)list 的赋值操作

    list.assign(beg, end); //将[beg, end)区间中的数据拷贝赋值给本身 1 #include <iostream> 2 #include <list> ...