[leetcode]669. Trim a Binary Search Tree寻找范围内的二叉搜索树
根据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寻找范围内的二叉搜索树的更多相关文章
- 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 ...
- 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 ...
- [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 ...
- 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 ...
- [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 ...
- [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. 这道 ...
- [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 ...
- 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 ...
- 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 ...
随机推荐
- [整理]qbxt集训10场考试 大 杂 烩 (前篇)
Contest 1 A 计算 \(n!\mod 2^{32}\) .发现数一大答案就为 \(0\) ,直接输出即可. B 一个 \(n\times m\) 的网格,网格中的数都在 \([1,nm]\) ...
- Spark存储Parquet数据到Hive,对map、array、struct字段类型的处理
利用Spark往Hive中存储parquet数据,针对一些复杂数据类型如map.array.struct的处理遇到的问题? 为了更好的说明导致问题的原因.现象以及解决方案,首先看下述示例: -- 创建 ...
- PyQt(Python+Qt)学习随笔:QDial刻度盘部件功能简介
专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 老猿学5G博文目录 一.概述 Designer中的Dial刻度盘输入部 ...
- PyQt(Python+Qt)学习随笔:QAbstractItemView的showDropIndicator属性
老猿Python博文目录 老猿Python博客地址 概述 QAbstractItemView的showDropIndicator属性用于控制在拖拽过程中显示当前拖拽到的位置,当释放时则在当前拖拽位置覆 ...
- python 练习洗牌
生成随机数需要引入random模块,学习下random模块中常用的几个函数: random.random() 用于生成一个0到1的随机符点数: 0 <= n < 1.0 random.un ...
- 【APIO2018】选圆圈(平面分块 | CDQ分治 | KDT)
Description 给定平面上的 \(n\) 个圆,用三个参数 \((x, y, R)\) 表示圆心坐标和半径. 每次选取最大的一个尚未被删除的圆删除,并同时删除所有与其相切或相交的圆. 最后输出 ...
- 在RAC上部署OGG并配置OGG高可用
目录 简介 环境信息 安装OGG 配置数据库 开启数据库级别日志补充 在dbdc1为OGG单独创建TNS 创建OGG管理用户及其表空间 配置OGG 设置OGG全局参数 Source端,OGG设置, 配 ...
- 主从复制架构直接转换MGR(manual)
环境信息 IP port role info 192.168.188.81 3316 node1 master 192.168.188.82 3316 node2 slave1 192.168.188 ...
- 前端js部署
1 执行命令 cnpm run build 2.2 提取dist静态资源 将静态资源放置后端static下 /static文件是django后端的部署文件夹 3 Nginx写入配置文件 写入etc ...
- centos7 安装netstat命令工具
[root@node01 yum.repos.d]# yum install -y net-tools Loaded plugins: fastestmirror Loading mirror spe ...