[LeetCode] 669.Trim a Binary Search Tree

LeetCode --- 669. Trim a Binary Search Tree 解题报告 Given a binary search tree and the lowest and highest boundaries asLandR, 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 se... 阅读详情

[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 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

解题思路

一道很简单的关于二叉搜索树的题目,解决这道题目的关键是明确二叉搜索树的概念,知道根节点和左右子节点之间的关系。判断L和R与节点的值的大小时出现的情况要想清楚,同时做出正确的递归。具体见代码。

实验代码

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
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;
    }
};
物体检测之非极大值抑制:NMS、softNMS、softerNMS、IoU-Net 当前的物体检测算法为了保证召回率,对于同一个真实物体往往会有多个的候选框输出。由于多余的候选框会影响检测精度,因此需要利用NMS过滤掉重叠的候选框,得到最佳的预测输出。当前有如下几种较为常见的NMS方法, 1.基本NMS 非极大值抑制, 顾名思义就是抑制不是极大值的边框,这里的抑制通常是直接去掉冗余的边框。 这个过程涉及以下两个量化指标: 1.预测得分:NMS假设一个边框的预测得分越高,这个框... 阅读详情

相关推荐

【论文翻译】VIT:An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale

VIT摘要介绍相关工作模型VISION TRANSFORMER (VIT)微调和高分辨率实验结论 摘要 虽然Transformer架构在自然语言处理任务中已经成为事实标准,但是它在计算机视觉领域的应用仍然受限。在视觉领域,注意力要么和卷积网络结合使用,要么替换卷积网络中的某些部分,同时保持整体结构不变。本文表明对CNNs的依赖不是必要的,纯转换器(pure transformer)直接应用于图像块(image patches)序列在图像分类任务中能发挥很好的作用。当对大量数据进行预训练并把它转移到多个中型或

栗子菜菜 1846

669. Trim a Binary Search Tree (Easy)

Given a binary search tree and the lowest and highest boundaries asLandR, 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 re...

weixin_30646315的博客 135

5种超实用方法:快速获取Windows文件夹下所有文件名(含CMD/PowerShell脚本)

本文详细介绍了5种快速获取Windows文件夹下所有文件名的实用方法,包括图形界面操作、Excel数据导入、CMD命令和PowerShell脚本。特别提供了高效的CMD和PowerShell脚本示例,帮助用户轻松实现文件名的批量获取与管理,大幅提升工作效率。

opencv7vision的博客 449

669. Trim a Binary Search Tree - Easy

Given a binary search tree and the lowest and highest boundaries asLandR, 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 re...

weixin_34329187的博客 171

不只是对齐:用 MFA 和 Praat 给你的语音数据集快速生成 TextGrid 标注文件

本文详细介绍了如何利用Montreal Forced Aligner(MFA)和Praat工具快速生成TextGrid标注文件,大幅提升语音数据标注效率。通过批量对齐、质量校验和跨语言处理等实战技巧,帮助研究者构建自动化标注流水线,适用于语音合成和语音识别等多种应用场景。

weixin_30675247的博客 378

OpenClaw + Antigravity + 飞书完整部署教程

在 Linux 服务器上部署 OpenClaw,使用 Antigravity 本地代理 AI 模型,并接入飞书实现 24 小时在线 AI 助手。

Maynor的博客 1788

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 all its elements lies in [L, R] (R >= L). You might need to change the root of the tree, so the r

淡然坊 2316

YOLOv9改进策略【注意力机制篇】| 添加SE、CBAM、ECA、CA、Swin Transformer等注意力和多头注意力机制

这篇文章带来一个经典注意力模块的汇总,虽然有些模块已经发布很久了,但后续的注意力模块也都是在此基础之上进行改进的,对于初学者来说还是有必要去学习了解一下,以加深对模块,模型的理解。

Limiiiing的博客 2892

LeetCode //C - 669. Trim a Binary Search Tree

【代码】LeetCode //C - 669. Trim a Binary Search Tree。

Made in Code 1212

【AI黑话日日新】什么是对比学习?

模型效果高度依赖大规模、高质量的人工标注数据。数据标注不仅成本高昂、周期漫长,在医疗、工业、小众垂类等场景中,甚至难以获取足量的标注样本,严重限制了模型的泛化能力与应用边界。自监督学习的出现,为解决这一问题提供了全新思路——无需人工标注标签,而是利用数据自身的结构与内在关联,构建自生成的监督信号完成模型预训练,再通过微调适配下游任务。在众多自监督学习方法中,对比学习(Contrastive Learning)

专注:太空算力、AI infra、异构调度、大模型成本工程 730

S/4HANA Private Cloud 与 On-Premise 的 Key User Custom Fields 运输与升级避坑指南

本文探讨了SAP S/4HANA Cloud Private Edition和On-Premise系统中Key User Custom Fields的管理要点。文章指出,Custom Fields涉及元数据生成、对象一致性、传输治理等完整链路,操作不当会导致字段丢失或升级失败。关键建议包括:使用ATO Fiori App管理扩展项与传输绑定,配置正确的job user权限,避免在多系统并行开发同一字段。特别强调升级时需执行CFD_REGENERATE_IN_ONPREMISE报表,并通过标准传输机制推进变更

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 195

【Leetcode】669. Trim a Binary Search Tree

题目地址: https://leetcode.com/problems/trim-a-binary-search-tree/ 给定一棵二叉搜索树,再给定一个范围[L,R][L,R][L,R],要求将这棵树所有在这个范围之外的节点都删掉,返回新树树根。 思路是用分治法。如果是空树则直接返回,否则看树根的范围,如果树根处于(−∞,L)(-\infty, L)(−∞,L),那说明树根以及整个左子树都要被...

数学、算法爱好者的博客 205

[Research Tips] 我的zotero文献管理方案: 云端同步+iPad批注+overleaf笔记

文献管理一直是一个很头疼的事. 最初直接在paper上做笔记, 后来尝试各种各样的文献管理软件, 比如endnote, mendeley等, 再后来直接用excel. 每一种方案都不是很满意. 最近尝试了各种软件, 摸索出一个合适自己的文献管理方案, 分享给大家. 我的需求: 支持PDF内全文搜索. 支持笔记搜索. 支持同步 可以批注PDF. 支持word内引用 支持Tex笔记语法 支持标签化管理 目前的方案除了第二个需求, 其他的都支持. 就目前我的经验来说, 除了知网研学可以搜索笔记外, 其他软件都

落日之城 5316

[leetcode]669. Trim a Binary Search Tree(Python)

[leetcode]669. Trim a Binary Search Tree题目描述题目理解解题思路递归Time 题目描述 Category:Easy Tree Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements ...

La_Ragazza的博客 441

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

[leetcode] 669. Trim a Binary Search Tree

Description 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 tre...

Learning from the mistakes 181

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

[Leetcode]669 Trim a Binary Search Tree

Given a binary search tree and the lowest and highest boundaries asLandR, 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 t...

Nicole852217677的专栏 107

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

[LeetCode] 669. Trim a Binary Search Tree

原题链接: https://leetcode.com/problems/trim-a-binary-search-tree/ 1. 题目介绍 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...

Ber03的博客 247

【LeetCode】669.Trim a Binary Search Tree解题报告

【LeetCode】669.Trim a Binary Search Tree解题报告tags: Tree题目地址:https://leetcode.com/problems/trim-a-binary-search-tree/description/ 题目描述:   Given a binary search tree and the lowest and highest boundarie

郝春雨的博客 251

LeetCode-669. Trim a Binary Search Tree [C++][Java]

Given therootof a binary search tree and the lowest and highest boundaries aslowandhigh, trim the tree so that all its elements lies in[low, high]. Trimming the tree shouldnotchange the relative structure of the elements

贫道绝缘子的博客 151

Leetcode 669. Trim a Binary Search Tree (python+cpp)

Leetcode 669. Trim a Binary Search Tree题目解析: 题目 解析: 如果当前节点在范围内,此节点不动,递归到下一层的左右子树 否则,根据当前节点的范围,直接返回左子树或者右子树 python代码如下: class Solution: def trimBST(self, root: TreeNode, L: int, R: int) -> TreeNode: def trim(node): if not node:

qq_37821701的博客 223

LeetCode669. Trim a Binary Search Tree

【代码】LeetCode669. Trim a Binary Search Tree。

叶卡捷琳堡的博客 359

[LeetCode]669. Trim a Binary Search Tree

[LeetCode]669. Trim a Binary Search Tree 题目描述 思路 递归 当前节点值未在规定范围内时,递归更新当前节点值到范围后,之后递归更新当前节点的左右子树 代码 #include using namespace std; struct TreeNode { int val; TreeNode* left; Tr

Lcharon的博客 474

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 all its elements lies in [L, R] (R >= L). You might need to change the root of the tree, so the result

菜园子 860
上一篇: [LeetCode] 620.Not Boring Movies
下一篇: [LeetCode] 167.Two Sum II - Input array is sorted
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值