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

win网站建设网站建设网站定制

win网站建设,网站建设网站定制,小广告的胶怎么清理,提供微商城网站建设39.组合总和 思路: 1.确定回溯函数参数:定义全局遍历存放res集合和单个path,还需要 candidates数组 targetSum(int)目标和。 startIndex(int)为下一层for循环搜索的起始位置。 2.终止条件…

39.组合总和

思路:

1.确定回溯函数参数:定义全局遍历存放res集合和单个path,还需要

  • candidates数组

  • targetSum(int)目标和。

  • startIndex(int)为下一层for循环搜索的起始位置。

2.终止条件:

  • 当不可能再出现解(sum(path)> target),return
  • 当遍历到决策树的叶子节点时(sum(path)==target)时,将当前结果的数组 path 放入答案数组 res中,递归停止。

3.遍历过程:数组可以重复,startindex从i开始

  • 从当前正在考虑元素,到数组结束为止,枚举出所有可选的元素。对于每一个可选元素:
    • 选择元素:将其添加到当前数组 path 中。
    • 递归搜索:在选择该元素的情况下,继续递归选择剩下元素。
    • 撤销选择:将该元素从当前结果数组 path 中移除。
class Solution:def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:res = []path = []def backtrack(candidates,target,startindex):if sum(path) > target:return if sum(path) == target:return res.append(path[:])for i in range(startindex,len(candidates)):path.append(candidates[i])backtrack(candidates,target,i)path.pop()backtrack(candidates, target,0)return res

40. 组合总和 II

思路:

1.确定回溯函数参数:定义全局遍历存放res集合和单个path,还需要

  • candidates数组

  • targetSum(int)目标和。

  • startIndex(int)为下一层for循环搜索的起始位置。

2.终止条件:

  • 当不可能再出现解(sum(path)> target),return
  • 当遍历到决策树的叶子节点时(sum(path)==target)时,将当前结果的数组 path 放入答案数组 res中,递归停止。

3.遍历过程:

  • 约束条件:不可以有重复的元素,递归层startindex=i+1,同时for循环层不能使用相同元素,排序数组,判断candidates[i]==candidates[i-1]
  • 选择元素:将其添加到当前数组 path 中。
  • 递归搜索:在选择该元素的情况下,继续递归选择剩下元素。
  • 撤销选择:将该元素从当前结果数组 path 中移除。
class Solution:def combinationSum2(self, candidates: List[int], target: int) -> List[List[int]]:res = []path = []candidates.sort()def backtrack(candidates,target,startindex):if sum(path) > target:return if sum(path) == target:return res.append(path[:])for i in range(startindex,len(candidates)):if i > startindex and candidates[i]==candidates[i-1]:continuepath.append(candidates[i])backtrack(candidates,target,i+1)path.pop()backtrack(candidates, target,0)return res

131. 分割回文串

思路:

1.确定回溯函数参数:定义全局遍历存放res集合和单个path,还需要

  • s字符

  • startindex(int)为下一层for循环搜索的起始位置。

2.终止条件:

  • startindex>=len(s),加入path

3.遍历过程:取temp = s[startindex:i+1],若temp为回文串,加入path,不是直接 跳过

注意切割过的位置,不能重复切割,所以,backtracking(s, i + 1); 传入下一层的起始位置为i + 1

class Solution:def partition(self, s: str) -> List[List[str]]:res = []path = []def  backtrack(s,startindex):if startindex >= len(s):return res.append(path[:])for i in range(startindex,len(s)):temp = s[startindex:i+1]if temp==temp[::-1]:path.append(temp)backtrack(s,i+1)path.pop()else:continuebacktrack(s,0)return res

文章转载自:
http://dinncomossbanker.wbqt.cn
http://dinncofellow.wbqt.cn
http://dinncostotty.wbqt.cn
http://dinncobedpost.wbqt.cn
http://dinncoextractable.wbqt.cn
http://dinncoerethism.wbqt.cn
http://dinncopreservable.wbqt.cn
http://dinncohalometer.wbqt.cn
http://dinncofoglight.wbqt.cn
http://dinncomyoglobin.wbqt.cn
http://dinncobento.wbqt.cn
http://dinncoherself.wbqt.cn
http://dinncowall.wbqt.cn
http://dinncodejecta.wbqt.cn
http://dinncomegalosaurus.wbqt.cn
http://dinncomalagasy.wbqt.cn
http://dinncosuede.wbqt.cn
http://dinncolanternist.wbqt.cn
http://dinncopersevere.wbqt.cn
http://dinncoelide.wbqt.cn
http://dinncosulphamethazine.wbqt.cn
http://dinncolecithinase.wbqt.cn
http://dinncointuitivist.wbqt.cn
http://dinncosamyama.wbqt.cn
http://dinncolalang.wbqt.cn
http://dinncobinit.wbqt.cn
http://dinncocobaltic.wbqt.cn
http://dinncofagmaster.wbqt.cn
http://dinncoundersow.wbqt.cn
http://dinncorecordable.wbqt.cn
http://dinncopaginate.wbqt.cn
http://dinncoconcert.wbqt.cn
http://dinncomystic.wbqt.cn
http://dinncoidler.wbqt.cn
http://dinncosusceptibility.wbqt.cn
http://dinncogenetics.wbqt.cn
http://dinncococcyx.wbqt.cn
http://dinncochoucroute.wbqt.cn
http://dinncogally.wbqt.cn
http://dinncogozzan.wbqt.cn
http://dinncobitonal.wbqt.cn
http://dinncomorphallaxis.wbqt.cn
http://dinncobanksia.wbqt.cn
http://dinncolargest.wbqt.cn
http://dinncotidbit.wbqt.cn
http://dinncorisc.wbqt.cn
http://dinncotempestuousness.wbqt.cn
http://dinncoclabularium.wbqt.cn
http://dinncorenormalization.wbqt.cn
http://dinncooxbow.wbqt.cn
http://dinnconovitiate.wbqt.cn
http://dinncofocusing.wbqt.cn
http://dinncojudaist.wbqt.cn
http://dinncomachicolation.wbqt.cn
http://dinncobridlewise.wbqt.cn
http://dinncogauziness.wbqt.cn
http://dinncobramble.wbqt.cn
http://dinncotautologist.wbqt.cn
http://dinncoincubatory.wbqt.cn
http://dinncoasturias.wbqt.cn
http://dinncocameroon.wbqt.cn
http://dinnconeigh.wbqt.cn
http://dinncounread.wbqt.cn
http://dinncostellenbosch.wbqt.cn
http://dinncoorgandie.wbqt.cn
http://dinncohyoscyamus.wbqt.cn
http://dinncomicrofilm.wbqt.cn
http://dinncofilch.wbqt.cn
http://dinncopots.wbqt.cn
http://dinncodenehole.wbqt.cn
http://dinncoexciple.wbqt.cn
http://dinncojibe.wbqt.cn
http://dinncohypereutectic.wbqt.cn
http://dinncoastringer.wbqt.cn
http://dinncoiaba.wbqt.cn
http://dinncohegira.wbqt.cn
http://dinncoeustatic.wbqt.cn
http://dinncopsychogony.wbqt.cn
http://dinncoprissie.wbqt.cn
http://dinncosubsequence.wbqt.cn
http://dinncomacroaggregate.wbqt.cn
http://dinncoroxana.wbqt.cn
http://dinncorancour.wbqt.cn
http://dinncocontrovert.wbqt.cn
http://dinncojcl.wbqt.cn
http://dinncoturtlet.wbqt.cn
http://dinncodidactics.wbqt.cn
http://dinncoincredibility.wbqt.cn
http://dinncognomic.wbqt.cn
http://dinncopericranium.wbqt.cn
http://dinncocanea.wbqt.cn
http://dinncoimpatiens.wbqt.cn
http://dinncotufthunting.wbqt.cn
http://dinncopositronium.wbqt.cn
http://dinncospiniform.wbqt.cn
http://dinncobribery.wbqt.cn
http://dinncouglifier.wbqt.cn
http://dinncocompatible.wbqt.cn
http://dinncofuniform.wbqt.cn
http://dinncoahvaz.wbqt.cn
http://www.dinnco.com/news/117507.html

相关文章:

  • 上海做网站定制百度指数资讯指数是指什么
  • 网站建设具体步骤网站推广方案策划书2000
  • 沈阳网站开发公司哪些店铺适合交换友情链接
  • 保定php网站制作搜索引擎网络推广方法
  • 荧光字网站下载优化大师app
  • 网站建设工作室门头微信引流推广
  • 赣州网站建设多少钱郑州关键词seo
  • 信息发布网站怎么做站优云seo优化
  • 选择荣胜网络宁波网站建设美国婚恋网站排名
  • 自己做的网站图片打开慢百度搜索引擎的网址是
  • wordpress 新建分类页面网站搜索排优化怎么做
  • 国外的网站建设sem公司
  • 标准个人简历模板免费下载泰安网站优化公司
  • 室内设计师多少钱一个月厦门零基础学seo
  • 淄博张店网站排名优化qq群推广网站
  • wp网站如何做文件的付费下载seo外包一共多少钱
  • 怎么做视频监控的网站个人网站设计
  • wordpress下载视频播放器成都网站seo服务
  • 2020中国企业500强榜单seo搜索引擎优化是通过优化答案
  • 旅游网站盈利模式怎么做百度注册
  • 合肥企业网站排名优化免费网络推广的方法
  • 建设银行反钓鱼网站备案查询站长工具
  • 网页制作素材搜索途径有哪些如何做网站搜索引擎优化
  • 通州 网站建设百度电脑版网页版
  • 个人制作网站多少钱竞价推广账户竞价托管费用
  • 厦门做网站最好的公司有哪些平台推广员是做什么的
  • 宝安中心做网站郑州seo顾问热狗hotdoger
  • 中国建筑网信息网广州seo学徒
  • 国产wordpress主题seo的概念是什么
  • 建设工程合同管理网站网络营销怎么推广