[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 ...
随机推荐
- 14_TTS
TTS(Text to speech)为语音合成的意思.本课程主要介绍了TTS的使用方法. 1 package cn.eoe.tts; 2 3 import java.util.Locale; 4 i ...
- java46
1.迭代器遍历 import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; public c ...
- Kafak探究之路- 内部结构小结
1.框架与工作流 2 内部结构 kafka的每个主题分区的数据在 first-0(主题名-分区号)文件夹下,保存 n组xxx.log文件与xxx.index文件.log文件存发送消息的元数据,每个大小 ...
- PyQt(Python+Qt)学习随笔:QTableWidgetItem项的复选状态checkState访问方法
老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 QTableWidget表格部件中的QTableWidgetItem项可以单独设置复选状态,如图所有 ...
- PyQt(Python+Qt)学习随笔:toolButton的toolButtonStyle属性
toolButtonStyle属性用于确认toolButton按钮显示文字.图标的方式,其类型为枚举类型 Qt.ToolButtonStyle,有如下值: ToolButtonIconOnly(值为0 ...
- Syclover 第十次极客大挑战web题题解
这次有空的时候报名参加了一下三叶草的招新比赛,比赛时间是一个月,题目都挺基础挺好玩的,在这里记一下自己的题解同时把自己没有做的题目也跟着writeup做一遍 第一题:cl4y:打比赛前先撸一只猫!: ...
- DVWA SQL Injection Medium
Mdeium 基本的步骤及知识点在上节已经提到过这里不再赘述:https://blog.csdn.net/WQ_BCJ/article/details/84554777 1)与low级别不同,本次采用 ...
- python-字典dict、去除重复set
dict Python内置了字典:dict的支持,dict全称dictionary,在其他语言中也称为map,使用键-值(key-value)存储,具有极快的查找速度. 举个例子,假设要根据同学的名字 ...
- google colab 杂谈
需要一个GPU服务器,找到了免费的Google Colab 一.切换tensorflow版本: %tensorflow_version 1.x import tensorflow as tf tf._ ...
- 【题解】AcWing 193. 算乘方的牛
原题链接 题目描述 约翰的奶牛希望能够非常快速地计算一个数字的整数幂P(1 <= P <= 20,000)是多少,这需要你的帮助. 在它们计算得到最终结果的过程中只能保留两个工作变量用于中 ...