653. Two Sum IV - Input is a BST [JavaScript]

一、题目

  Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target.

二、题目大意

  二叉搜索树中是否存在两个元素的值为k。

三、解题思路

  递归遍历二叉树。

四、代码实现
const findTarget = (root, k) => {
  const ans = []

  help(root)

  const max = ans.length
  for (let i = 0; i < max; i++) {
    for (let j = i + 1; j < max; j++) {
      const pre = ans[i]
      const next = ans[j]
      if (pre + next === k) {
        return true
      }
    }
  }

  return false

  function help (root) {
    if (!root) {
      return
    }
    help(root.left)
    ans.push(root.val)
    help(root.right)
  }
}

  如果本文对您有帮助,欢迎关注微信公众号,为您推送更多大前端相关的内容, 欢迎留言讨论,ε=ε=ε=┏(゜ロ゜;)┛。

  您还可以在这些地方找到我:

资源下载链接为: https://pan.quark.cn/s/22ca96b7bd39 在当今的软件开发领域,自动化构建与发布是提升开发效率和项目质量的关键环节。Jenkins Pipeline作为一种强大的自动化工具,能够有效助力Java项目的快速构建、测试及部署。本文将详细介绍如何利用Jenkins Pipeline实现Java项目的自动化构建与发布。 Jenkins Pipeline简介 Jenkins Pipeline是运行在Jenkins上的一套工作流框架,它将原本分散在单个或多个节点上独立运行的任务串联起来,实现复杂流程的编排与可视化。它是Jenkins 2.X的核心特性之一,推动了Jenkins从持续集成(CI)向持续交付(CD)及DevOps的转变。 创建Pipeline项目 要使用Jenkins Pipeline自动化构建发布Java项目,首先需要创建Pipeline项目。具体步骤如下: 登录Jenkins,点击“新建项”,选择“Pipeline”。 输入项目名称和描述,点击“确定”。 在Pipeline脚本中定义项目字典、发版脚本和预发布脚本。 编写Pipeline脚本 Pipeline脚本是Jenkins Pipeline的核心,用于定义自动化构建和发布的流程。以下是一个简单的Pipeline脚本示例: 在上述脚本中,定义了四个阶段:Checkout、Build、Push package和Deploy/Rollback。每个阶段都可以根据实际需求进行配置和调整。 通过Jenkins Pipeline自动化构建发布Java项目,可以显著提升开发效率和项目质量。借助Pipeline,我们能够轻松实现自动化构建、测试和部署,从而提高项目的整体质量和可靠性。
我使用IEEE 的latex检查器,上传文件显示有一个错误和两个警告 This is BibTeX, Version 0.99d (TeX Live 2024) Capacity: max_strings=200000, hash_size=200000, hash_prime=170003 The top-level auxiliary file: output.aux The style file: IEEEtran.bst Reallocated singl_function (elt_size=4) to 100 items from 50. Reallocated singl_function (elt_size=4) to 100 items from 50. Reallocated singl_function (elt_size=4) to 100 items from 50. Reallocated wiz_functions (elt_size=4) to 6000 items from 3000. Reallocated singl_function (elt_size=4) to 100 items from 50. Database file #1: reference.bib Repeated entry---line 360 of file reference.bib : @article{10429768 : , I'm skipping whatever remains of this entry -- IEEEtran.bst version 1.14 (2015/08/26) by Michael Shell. -- http://www.michaelshell.org/tex/ieeetran/bibtex/ -- See the "IEEEtran_bst_HOWTO.pdf" manual for usage information. Done. You've used 30 entries, 4087 wiz_defined-function locations, 995 strings with 12414 characters, and the built_in function-call counts, 26851 in all, are: = -- 2276 > -- 614 < -- 288 + -- 372 - -- 94 * -- 1308 := -- 3935 add.period$ -- 60 call.type$ -- 30 change.case$ -- 30 chr.to.int$ -- 633 cite$ -- 30 duplicate$ -- 1870 empty$ -- 1894 format.name$ -- 120 if$ -- 6326 int.to.chr$ -- 0 int.to.str$ -- 30 missing$ -- 294 newline$ -- 113 num.names$ -- 29 pop$ -- 569 preamble$ -- 1 purify$ -- 0 quote$ -- 2 skip$ -- 2112 stack$ -- 0 substring$ -- 1522 swap$ -- 1702 text.length$ -- 77 text.prefix$ -- 0 top$ -- 5 type$ -- 30 warning$ -- 0 while$ -- 114 width$ -- 32 write$ -- 339 (There was 1 error message)
03-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值