[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 ...
随机推荐
- 图像处理术语解释:什么是PRGBA和Alpha预乘(Premultiplied Alpha )
☞ ░ 前往老猿Python博文目录 ░ Alpha预乘(Premultiplied Alpha)和PRGBA 一般来说四通道图像数据保存的都是ARGB或RGBA,其R.G.B值还没有进行任何透明化处 ...
- Python正则表达式处理的组是什么?
在学习正则表达式处理开始阶段,对于匹配对象的group数据没有理解,查了资料进行验证测试,终于理解了. 组其实与组匹配模式相关,就是在匹配的正则表达式中使用小括号"()"括起来的任 ...
- PyQt(Python+Qt)学习随笔:QListView的wordWrap属性
老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 QListView的wordWrap属性与QTableView的wordWrap属性功能完全相同,用 ...
- Object.prototype.toString.call()为什么可以用来检测数据类型?
obj.toString()方法是用来干什么的 每一个对象都有一个toString()方法,默认情况下toString()被每一个Object对象继承,如果此方法未被重写,toString()返回&q ...
- Linux使用inode(i节点号)删除文件
今天学习Linux的时候遇到的知识点,想起了以前一次线下AWD攻防赛的时候的不死马,记录一下 在Linux里面,有的时候我们会遇到奇奇怪怪的文件名,以至于我们删除不了,比如说我们创建了一个叫做&quo ...
- centos7最小安装后——网络配置、常见命令安装,远程连接、yum源安装软件包
安装环境 #软件:vmware 14 #centos版本:CentOS-7-x86_64-DVD-1810 下载地址: #网络配置:NAT模式 配置 网络配置 #动态获取ip: centos7最小安装 ...
- 转载 HTTP协议
转载自:http://www.cnblogs.com/TankXiao/archive/2012/02/13/2342672.html 当今web程序的开发技术真是百家争鸣,ASP.NET, PHP, ...
- BJOI2015 隐身术
落谷. Description 给你两个串 \(A.B\).询问 \(B\) 中有多少个非空子串和 \(A\) 的编辑距离不超过 \(K\). Solution 发现 \(K \le 5\),考虑可以 ...
- 题解-[SDOI2014]数数
[SDOI2014]数数 这题的前置知识是AC自动机和dp,前置题目是 [JSOI2007]文本生成器,前置题目我写的题解 题解-[JSOI2007]文本生成器.我的讲解假设你做过上面那道题. 这题比 ...
- 四、java多线程核心技术——synchronized同步方法与synchronized同步快
一.synchronized同步方法 论:"线程安全"与"非线程安全"是多线程的经典问题.synchronized()方法就是解决非线程安全的. 1.方法内的变 ...