leetcode_669.Trim a Binary Search Tree?待解决

来源:互联网 发布:昆明暴恐 中国公知 编辑:程序博客网 时间:2024/06/09 22:15

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 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 = 2

Output:
1
\
2
Example 2:
Input:
3
/ \
0 4
\
2
/
1

L = 1
R = 3

Output:
3
/
2
/
1

提示:提交代码后,需要用简洁的语言解释一下代码思路~ 谢谢

历史题目和总结见公众号「每日一道算法题」

https://leetcode.com/problems/trim-a-binary-search-tree/description/

思路: