669. Trim a Binary Search Tree
来源:互联网 发布:mac梦幻西游更新不了 编辑:程序博客网 时间:2024/06/06 04:02
Given a binary search tree and the lowest and highest boundaries as L
and R
, trim the tree so that all its elements lies in [L, R]
(R >= L). You might need to change the root of the tree, so the result should return the new root of the trimmed binary search tree.
Example 1:
Input: 1 / \ 0 2 L = 1 R = 2Output: 1 \ 2
Example 2:
Input: 3 / \ 0 4 \ 2 / 1 L = 1 R = 3Output: 3 / 2 /1
- 当root的值位于
L
和R
之间,则递归修剪其左右子树,返回root。 - 当root的值小于
L
,则其左子树的值都小于L
,抛弃左子树,返回修剪过的右子树。 - 当root的值大于
R
,则其右子树的值都大于R
,抛弃右子树,返回修剪过的左子树。
阅读全文
0 0
- leetcode 669. Trim a Binary Search Tree
- leetcode 669. Trim a Binary Search Tree
- leetcode 669. Trim a Binary Search Tree
- 669. Trim a Binary Search Tree
- 669. Trim a Binary Search Tree
- LeetCode 669. Trim a Binary Search Tree
- leetcode 669. Trim a Binary Search Tree
- 669. Trim a Binary Search Tree
- leetcode: 669. Trim a Binary Search Tree
- <LeetCode>669. Trim a Binary Search Tree
- leetcode 669. Trim a Binary Search Tree
- 669. Trim a Binary Search Tree
- LeetCode 669. Trim a Binary Search Tree
- [LeetCode] 669.Trim a Binary Search Tree
- 669. Trim a Binary Search Tree
- 669. Trim a Binary Search Tree
- 669. Trim a Binary Search Tree
- 669. Trim a Binary Search Tree
- WPF自定义搜索控件
- HTML5 WEBGL学习1 3D基础知识
- Android设计模式
- tf.gfile.FastGFile()
- HTTP请求状态码大全
- 669. Trim a Binary Search Tree
- 安装nginx和 nginx负载均衡
- 一只程序猿的养成日记 第一章 第十节 递归和非递归分别实现求第n个斐波那契数
- 左侧导航栏
- 7-7 螺旋方阵(20 分)
- jdk源码阅读之AbstractList
- 2017-12-15 centos 7 lamp环境搭建
- 不需要旋转,却能力压群雄的数据结构——非旋Treap 看完还不会你打我
- 中国科技大学网站