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

网站建设1000字沧州建设厅官方网站

网站建设1000字,沧州建设厅官方网站,做网站广告费,公众号开发的可行性39.组合总和 思路#xff1a; 1.确定回溯函数参数#xff1a;定义全局遍历存放res集合和单个path#xff0c;还需要 candidates数组 targetSum#xff08;int#xff09;目标和。 startIndex#xff08;int#xff09;为下一层for循环搜索的起始位置。 2.终止条件…39.组合总和 思路 1.确定回溯函数参数定义全局遍历存放res集合和单个path还需要 candidates数组 targetSumint目标和。 startIndexint为下一层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 res40. 组合总和 II 思路 1.确定回溯函数参数定义全局遍历存放res集合和单个path还需要 candidates数组 targetSumint目标和。 startIndexint为下一层for循环搜索的起始位置。 2.终止条件 当不可能再出现解(sum(path) target)return当遍历到决策树的叶子节点时(sum(path)target)时将当前结果的数组 path 放入答案数组 res中递归停止。 3.遍历过程 约束条件不可以有重复的元素递归层startindexi1同时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,i1)path.pop()backtrack(candidates, target,0)return res131. 分割回文串 思路 1.确定回溯函数参数定义全局遍历存放res集合和单个path还需要 s字符 startindexint为下一层for循环搜索的起始位置。 2.终止条件 startindexlen(s)加入path 3.遍历过程取temp s[startindex:i1]若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:i1]if temptemp[::-1]:path.append(temp)backtrack(s,i1)path.pop()else:continuebacktrack(s,0)return res
http://www.dnsts.com.cn/news/94623.html

相关文章:

  • 官方网站建设费用WordPress中文章固定链接
  • 微网站怎么免费做注册公司没有地址怎么弄
  • 广东金东建设工程公司网站网站做301根目录在哪里
  • 人力网站建设的建议怎么做一个公众号微信
  • 支付网站设计汉中网站建设
  • 网站标题正确书写标准怎么查网站是那个公司做的
  • 玉林网站设计外贸业务员怎么开发客户
  • 无锡网站制作哪家实惠巩义便宜网站建设
  • 网站设置为应用程序网站如何做电脑和手机app
  • 公司网站建设模板免费建com网站
  • 大学生家教网站开发网站建设挣钱的需要什么
  • 网站建设管理人员推荐表上海网络推广软件
  • 太原微商网站建设网站制作与网站建设
  • wordpress图片模板百度网站优化软件
  • 河北建设教育培训网站成都网站优化费用
  • 公司建设电商型网站的作用重庆建筑安全信息网
  • 免费做 爱视频网站上海高端网站定制建设公司
  • 关键词优化公司网站30几岁的人想学做网站
  • 一般的手机网站建设多少钱做网站一定要自己搭建服务器吗
  • 网站建设晋icp备开放平台 的优势 传统门户网站
  • 大型网站开发pdf中国国际贸易网官网
  • 想搭建网站学什么聊城网页设计公司
  • 网站简繁转换seo公司推广宣传
  • 软文网站名称天津网站建设座机号
  • 做那个的视频网站上海做网站大的公司
  • 网站开发登录链接广州建网站腾虎
  • 卡片式网站含山县建设局网站
  • 网站建设的数据库连接html酒店网站模板
  • 外贸是先做网站还是做阿里巴巴mui做浏览器网站跳转
  • 沈阳关键字优化公司seo优化的网站