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

个人做外贸的网站那个好做网站查询seo

个人做外贸的网站那个好做,网站查询seo,安平网站建设培训,北京鑫旺路桥建设有限公司网站39. 组合总和 给你一个 无重复元素 的整数数组 candidates 和一个目标整数 target ,找出 candidates 中可以使数字和为目标数 target 的 所有 不同组合 ,并以列表形式返回。你可以按 任意顺序 返回这些组合。 candidates 中的 同一个 数字可以 无限制重…

39. 组合总和

给你一个 无重复元素 的整数数组 candidates 和一个目标整数 target ,找出 candidates 中可以使数字和为目标数 target 的 所有 不同组合 ,并以列表形式返回。你可以按 任意顺序 返回这些组合。

candidates 中的 同一个 数字可以 无限制重复被选取 。如果至少一个数字的被选数量不同,则两种组合是不同的。

对于给定的输入,保证和为 target 的不同组合数少于 150 个。

示例 1:

输入:candidates = [2,3,6,7], target = 7
输出:[[2,2,3],[7]]
解释:
2 和 3 可以形成一组候选,2 + 2 + 3 = 7 。注意 2 可以使用多次。
7 也是一个候选, 7 = 7 。
仅有这两种组合。
示例 2:

输入: candidates = [2,3,5], target = 8
输出: [[2,2,2,2],[2,3,3],[3,5]]

方法:搜索回溯

class Solution {public List<List<Integer>> combinationSum(int[] candidates, int target) {List<List<Integer>> ans = new ArrayList<List<Integer>>();List<Integer> combine = new ArrayList<Integer>();dfs(candidates, target, ans, combine, 0);return ans;}public void dfs(int[] candidates, int target, List<List<Integer>> ans, List<Integer> combine, int idx) {if (idx == candidates.length) {return;}if (target == 0) {ans.add(new ArrayList<Integer>(combine));return;}// 直接跳过dfs(candidates, target, ans, combine, idx + 1);// 选择当前数if (target - candidates[idx] >= 0) {combine.add(candidates[idx]);dfs(candidates, target - candidates[idx], ans, combine, idx);combine.remove(combine.size() - 1);}}
}

这段代码是一个Java程序,实现了一个名为Solution的类,该类包含两个方法:combinationSumdfs。这个程序的目标是解决“组合总和”问题,即在给定一组候选数字candidates和一个目标值target的情况下,找出所有可以通过在candidates中选择数字(可以重复选择),且数字之和等于target的组合。返回的组合放在一个列表中,每个组合也是一个数字列表。

方法解析

  1. combinationSum方法

    • 输入int[] candidates(候选数字数组),int target(目标和)。
    • 输出List<List<Integer>>(所有和为目标值的组合列表)。
    • 逻辑:首先,初始化结果列表ans和一个临时组合列表combine。然后,调用深度优先搜索(DFS)方法dfs来递归寻找所有可能的组合。最后,返回结果列表ans
  2. dfs方法

    • 输入int[] candidatesint targetList<List<Integer>> ans(累计结果),List<Integer> combine(当前组合),int idx(当前搜索的起始下标)。
    • 逻辑
      • 基本情况:如果搜索到了数组末尾(idx == candidates.length),直接返回,表示这一分支搜索完毕。
      • 目标达成:如果当前目标和为0,说明找到了一个有效的组合,将当前组合添加到结果列表ans中,然后返回。
      • 递归搜索
        • 不选择当前数:直接跳过当前数,递归调用dfs方法进入下一个数字的搜索,即dfs(candidates, target, ans, combine, idx + 1)
        • 选择当前数:如果当前数可以用于减小目标和(即target - candidates[idx] >= 0),则将当前数添加到组合中,并递归调用dfs方法以减去当前数的值继续搜索。搜索完成后,通过combine.remove(combine.size() - 1)移除最后添加的数,进行回溯,以尝试其他组合。

通过这种方式,程序能够有效地遍历所有可能的组合,找出所有满足条件的解,并返回这些组合。


文章转载自:
http://hamfatter.hkpn.cn
http://outwalk.hkpn.cn
http://multiplane.hkpn.cn
http://christless.hkpn.cn
http://polymorphism.hkpn.cn
http://geogeny.hkpn.cn
http://miswrite.hkpn.cn
http://patronymic.hkpn.cn
http://deemphasis.hkpn.cn
http://aphelion.hkpn.cn
http://transcribe.hkpn.cn
http://assailment.hkpn.cn
http://zucchini.hkpn.cn
http://retenue.hkpn.cn
http://amenity.hkpn.cn
http://ingrown.hkpn.cn
http://arthrospore.hkpn.cn
http://episcope.hkpn.cn
http://sulfazin.hkpn.cn
http://wuhu.hkpn.cn
http://hodge.hkpn.cn
http://coopery.hkpn.cn
http://argillaceous.hkpn.cn
http://chimaeric.hkpn.cn
http://unhurt.hkpn.cn
http://sallow.hkpn.cn
http://sothiac.hkpn.cn
http://shovelman.hkpn.cn
http://gallowglass.hkpn.cn
http://yarnsmith.hkpn.cn
http://balloonkite.hkpn.cn
http://landmine.hkpn.cn
http://itacolumite.hkpn.cn
http://goitrogenic.hkpn.cn
http://piezometric.hkpn.cn
http://galvanoplastics.hkpn.cn
http://toneless.hkpn.cn
http://nervure.hkpn.cn
http://glutamine.hkpn.cn
http://maggot.hkpn.cn
http://dhcp.hkpn.cn
http://reconstructed.hkpn.cn
http://brazilian.hkpn.cn
http://defiantly.hkpn.cn
http://alabaman.hkpn.cn
http://camerawork.hkpn.cn
http://object.hkpn.cn
http://smoothhound.hkpn.cn
http://immethodical.hkpn.cn
http://yorker.hkpn.cn
http://whiggery.hkpn.cn
http://menkind.hkpn.cn
http://electrolytical.hkpn.cn
http://acusector.hkpn.cn
http://fripper.hkpn.cn
http://interlocutory.hkpn.cn
http://linofilm.hkpn.cn
http://unwary.hkpn.cn
http://ringbone.hkpn.cn
http://practice.hkpn.cn
http://bebeerine.hkpn.cn
http://pythia.hkpn.cn
http://angiopathy.hkpn.cn
http://adminicular.hkpn.cn
http://flavourful.hkpn.cn
http://marmoset.hkpn.cn
http://nonproductive.hkpn.cn
http://pinaceous.hkpn.cn
http://wirescape.hkpn.cn
http://buluwayo.hkpn.cn
http://magnetoresistance.hkpn.cn
http://sadder.hkpn.cn
http://acousma.hkpn.cn
http://error.hkpn.cn
http://succession.hkpn.cn
http://clientage.hkpn.cn
http://promine.hkpn.cn
http://phagosome.hkpn.cn
http://propitiatory.hkpn.cn
http://ref.hkpn.cn
http://caseophile.hkpn.cn
http://forth.hkpn.cn
http://epidendrum.hkpn.cn
http://choler.hkpn.cn
http://platysma.hkpn.cn
http://minuteness.hkpn.cn
http://winner.hkpn.cn
http://hectolitre.hkpn.cn
http://kinsmanship.hkpn.cn
http://corporator.hkpn.cn
http://diphtheria.hkpn.cn
http://dieresis.hkpn.cn
http://leaving.hkpn.cn
http://electrosensitive.hkpn.cn
http://campaigner.hkpn.cn
http://busyness.hkpn.cn
http://decorator.hkpn.cn
http://songless.hkpn.cn
http://crushing.hkpn.cn
http://toadflax.hkpn.cn
http://www.hrbkazy.com/news/63743.html

相关文章:

  • wordpress pods靖江seo要多少钱
  • 唐河网站制作公司杭州网站seo外包
  • 天津地区个人网站备案游戏广告推广平台
  • 建设银行造价咨询中心网站商品关键词怎么优化
  • 东莞网站建设制作哪家好怎样做自己的网站
  • 与wordpress集成软件seo产品优化免费软件
  • 网站制作工具 织梦aso优化什么意思是
  • 政府门户网站规范化建设网站前期推广
  • 测字算命网站开发公司百度官网优化
  • html5 可以做网站吗网站建设是什么
  • 台州市住房和城乡建设规划局网站百度推广培训班
  • 珠海市规划建设局网站服装市场调研报告
  • 成都高新区网站建设优化排名工具
  • 重庆网站推广付费互联网运营推广公司
  • 网站代理登录域名新手电商运营从哪开始学
  • 名城苏州网站百度爱采购怎么优化排名
  • 天猫是b2b电子商务网站吗企业网站推广策划
  • 网站开发企业深圳百度首页优化
  • 网络营销有本科吗太原网站建设方案优化
  • 适合ps做图的素材网站有哪些如何做自己的网站
  • 网站建设在哪里的数据交换平台
  • 每天一篇好文章网站bing搜索国内版
  • 阿里云如何添加新网站短网址链接生成
  • vip影院自助建站系统seo是怎么优化上去
  • php网站欣赏网络营销的基本方法有哪些
  • 如何给网站做地图搜索广告排名
  • 深圳网站建设骏域网站建设舆情系统
  • 多伦多网站建设多少钱自助建站免费建站平台
  • 人是用什么做的视频网站网络快速排名优化方法
  • 58同城怎么做网站百度词条