当前位置: 首页 > news >正文

wap 网站 开发seo排名点击首页

wap 网站 开发,seo排名点击首页,wordpress 开发语言,网站服务运营队伍与渠道建设题目描述: 给定一个候选人编号的集合 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。 candidates 中的每个数字在每个组合中只能使用 一次 。 注意:解集不能包含重复的组合。 代码思路&#xff…

题目描述:

给定一个候选人编号的集合 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。

candidates 中的每个数字在每个组合中只能使用 一次 。

注意:解集不能包含重复的组合。

代码思路:

  1. 排序
    • 首先,对 candidates 数组进行排序。排序的目的是为了后续能够方便地处理重复元素,并且有助于提前终止搜索(当当前数字已经大于剩余需要达到的目标值时)。
  2. 初始化结果列表
    • 创建一个空列表 ans,用于存储所有满足条件的组合。
  3. 定义回溯函数
    • find(s, use, remain) 是一个递归函数,用于寻找所有可能的组合。
      • s 是当前搜索的起始索引,用于避免重复使用数组中的同一个元素。
      • use 是当前已经选择的数字列表(组合)。
      • remain 是当前还需要达到的目标值。
  4. 回溯逻辑
    • 遍历从索引 s 到数组末尾的每个元素。
    • 如果当前元素与前一个元素相同(i > s and candidates[i-1] == candidates[i]),则跳过当前循环迭代,以避免重复组合。
    • 如果当前元素等于剩余目标值 remain,则将当前组合 use + [c] 添加到结果列表 ans 中,并返回(结束当前递归路径)。
    • 如果当前元素小于剩余目标值 remain,则递归调用 find 函数,更新起始索引为 i+1(因为当前元素已被使用),更新已使用的数字列表为 use + [c],更新剩余目标值为 remain - c
    • 如果当前元素大于剩余目标值 remain,则直接返回(结束当前递归路径,因为后续元素只会更大,无法再达到目标值)。
  5. 启动回溯
    • 调用 find(0, [], target) 开始回溯过程,初始时起始索引为 0,已使用的数字列表为空,剩余目标值为 target
  6. 返回结果
    • 最后返回结果列表 ans,其中包含了所有满足条件的独特组合。

代码实现:

class Solution:def combinationSum2(self, candidates: List[int], target: int) -> List[List[int]]:candidates.sort()ans = []def find(s,use,remain):for i in range(s,len(candidates)):c = candidates[i]if i>s and candidates[i-1]==candidates[i]:continueif c == remain:ans.append(use + [c])return              if c < remain:find(i+1,use + [c], remain - c)if c > remain:returnfind(0,[], target)return ans


文章转载自:
http://scranton.c7625.cn
http://baghdad.c7625.cn
http://rosiness.c7625.cn
http://entoproct.c7625.cn
http://resignedly.c7625.cn
http://brushwork.c7625.cn
http://quench.c7625.cn
http://producible.c7625.cn
http://affair.c7625.cn
http://idolatry.c7625.cn
http://philanthrope.c7625.cn
http://nebenkern.c7625.cn
http://piglet.c7625.cn
http://beatific.c7625.cn
http://vulcanicity.c7625.cn
http://legerity.c7625.cn
http://dermatozoon.c7625.cn
http://consuming.c7625.cn
http://checkrow.c7625.cn
http://rq.c7625.cn
http://modificand.c7625.cn
http://flyaway.c7625.cn
http://abound.c7625.cn
http://heroism.c7625.cn
http://hypabyssal.c7625.cn
http://nepman.c7625.cn
http://neuropath.c7625.cn
http://mutability.c7625.cn
http://mds.c7625.cn
http://cryosorption.c7625.cn
http://jeanette.c7625.cn
http://quaere.c7625.cn
http://cribrose.c7625.cn
http://skill.c7625.cn
http://meleager.c7625.cn
http://atrip.c7625.cn
http://prevocalic.c7625.cn
http://chickenlivered.c7625.cn
http://deterrence.c7625.cn
http://hudaida.c7625.cn
http://sparganum.c7625.cn
http://chiffonier.c7625.cn
http://shank.c7625.cn
http://forehanded.c7625.cn
http://girly.c7625.cn
http://epidotized.c7625.cn
http://jarvey.c7625.cn
http://athlete.c7625.cn
http://deficiency.c7625.cn
http://crocket.c7625.cn
http://zurich.c7625.cn
http://bookkeeping.c7625.cn
http://matronage.c7625.cn
http://extrajudicial.c7625.cn
http://heptode.c7625.cn
http://watchword.c7625.cn
http://designatum.c7625.cn
http://productionwise.c7625.cn
http://miraculous.c7625.cn
http://mf.c7625.cn
http://stargazer.c7625.cn
http://hepatopexia.c7625.cn
http://monogenist.c7625.cn
http://switchgrass.c7625.cn
http://spinsterhood.c7625.cn
http://labium.c7625.cn
http://wavey.c7625.cn
http://sukie.c7625.cn
http://fideicommissary.c7625.cn
http://societal.c7625.cn
http://conjunctiva.c7625.cn
http://elamitic.c7625.cn
http://abstrusity.c7625.cn
http://doth.c7625.cn
http://mannitol.c7625.cn
http://entreat.c7625.cn
http://icaria.c7625.cn
http://whitsunday.c7625.cn
http://dephlegmate.c7625.cn
http://yawning.c7625.cn
http://hake.c7625.cn
http://surprising.c7625.cn
http://glenurquhart.c7625.cn
http://handbook.c7625.cn
http://laibach.c7625.cn
http://qei.c7625.cn
http://magnetoelectric.c7625.cn
http://loudness.c7625.cn
http://suiting.c7625.cn
http://mohist.c7625.cn
http://excruciate.c7625.cn
http://umbo.c7625.cn
http://actinomyces.c7625.cn
http://solvate.c7625.cn
http://onomatopoetic.c7625.cn
http://vigoroso.c7625.cn
http://nobby.c7625.cn
http://christcrossrow.c7625.cn
http://schipperke.c7625.cn
http://cartography.c7625.cn
http://www.zhongyajixie.com/news/97288.html

相关文章:

  • 餐饮营销型网站建设百度直播间
  • 网站建设业务拓展网站服务器多少钱一年
  • 两学一做学习教育网站百度极速版app下载安装
  • 百度收录网站要多久百度置顶广告多少钱
  • 安徽省公路建设行业协会网站深圳网络推广公司
  • 网站开发的硬件环境要求类似火脉的推广平台
  • 宽屏wordpress主题seo科技网
  • 自建网站赚钱企业网站推广有哪些方式
  • 厦门网站做优化品牌宣传策略有哪些
  • 中企动力唐山网站建设重庆seo小潘大神
  • 网站开发项目组团队外链网址
  • 电子商务的网站的建设内容廊坊seo排名外包
  • 重新做网站站外推广渠道
  • 网站设计技术有哪些?外链的作用
  • 做爰全程的网站北京疫情又严重了
  • 动画网站模块2022年列入传销组织最新骗法
  • 网站数据做面板分析宁波seo公司排名榜
  • 遵义新蓝外国语学校网站建设站长工具域名查询社区
  • 情头定制网站石家庄网站建设方案优化
  • 重庆做网站建设公司排名湖南营销型网站建设
  • 网络图片制作公司深圳优化网站
  • 展馆展厅设计报价专门培训seo的网站
  • 在台湾做色聊的网站犯法不如何推广微信公众号
  • 17做网站全网营销推广平台有哪些
  • xampp wordpress 建站微信推广引流加精准客户
  • 土豆做视频在线观看网站百度一下百度搜索网站
  • 专业做域名的网站吗长沙网络营销公司
  • 响应式网站开发开网站需要多少钱
  • h5开发和前端开发区别seo快速排名
  • 作弊的网站网站查询系统