LeetCode 669. 修剪二叉搜索树(Trim a Binary Search Tree)
2024-10-21 04:11:15
669. 修剪二叉搜索树
669. Trim a Binary Search Tree
题目描述
LeetCode669. Trim a Binary Search Tree简单
Java 实现
TreeNode Class
public class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode(int x) {
val = x;
}
}
class Solution {
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);
}
root.left = trimBST(root.left, L, R);
root.right = trimBST(root.right, L, R);
return root;
}
}
参考资料
- https://www.cnblogs.com/grandyang/p/7583185.html
- https://leetcode-cn.com/problems/trim-a-binary-search-tree/
- https://leetcode.com/problems/trim-a-binary-search-tree/
最新文章
- Exception in thread ";main"; java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli :
- 说一说inline-block的奇葩之处
- Windows 服务器开通防火墙后,IISFTP和Serv U开通的FTP账号不能登录
- shell脚本修复MySQL主从同步
- This application failed to start because it could not find or load the Qt platform plugin ";windows";
- 2761: [JLOI2011]不重复数字(哈希表)
- JavaScript异步加载的三种方式——async和defer、动态创建script
- MongoDB + Express 环境搭建记
- 分布式任务&;分布式锁
- android-基础编程-Preference
- 转:SQL 关于apply的两种形式cross apply 和 outer apply
- 【RF库XML测试】通过xpath查找元素的说明
- springboot-5-整合jpa
- 创建工具条ToolBar
- Java加密代码 转换成Net版
- 使用bootstrap时碰到问题$(...).modal is not a function
- 搜索二维矩阵 II
- Entity Framework查询生成大量的子查询,如何避免?求救
- SAN,NAS,DAS的差别
- 在有主分支和个人分支情况下的TFS使用方法