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

天河网站设计免费微网站系统源码

天河网站设计,免费微网站系统源码,wordpress前端怎么写,孝感网站建设专家回溯 1、39. 组合总和 题目#xff1a; 给你一个 无重复元素 的整数数组 candidates 和一个目标整数 target #xff0c;找出 candidates 中可以使数字和为目标数 target 的 所有 不同组合 #xff0c;并以列表形式返回。你可以按 任意顺序 返回这些组合。 candidates 中的…回溯 1、39. 组合总和 题目 给你一个 无重复元素 的整数数组 candidates 和一个目标整数 target 找出 candidates 中可以使数字和为目标数 target 的 所有 不同组合 并以列表形式返回。你可以按 任意顺序 返回这些组合。 candidates 中的 同一个 数字可以 无限制重复被选取 。如果至少一个数字的被选数量不同则两种组合是不同的。 对于给定的输入保证和为 target 的不同组合数少于 150 个。 输入candidates [2,3,6,7], target 7 输出[[2,2,3],[7]] 思路 第二次写了很简单就写出来了注意 2 可以使用多次。_backtrack(res, list,candidates, target,sum, i1),不要i1 func combinationSum(candidates []int, target int) [][]int {// 代码二刷很经典回溯list : make([]int, 0)res : make([][]int, 0)backtrack(res, list,candidates,target,0,0)return res } func backtrack(res *[][]int, list,candidates []int, target, sum,index int) {if sum target {ans : make([]int, len(list))copy(ans, list)*res append(*res, ans)return}if sum target {return}for i : index; ilen(candidates); i {sum candidates[i]list append(list, candidates[i])backtrack(res, list,candidates, target,sum, i)sum - candidates[i]list list[:len(list)-1]} }2、40. 组合总和 II 题目 给定一个候选人编号的集合 candidates 和一个目标数 target 找出 candidates 中所有可以使数字和为 target 的组合。 candidates 中的每个数字在每个组合中只能使用 一次 。 注意解集不能包含重复的组合。 输入: candidates [10,1,2,7,6,1,5], target 8, 输出: [ [1,1,6], [1,2,5], [1,7], [2,6] ] 思路 怎么去重呢?使用 historyelse if sum target 记得这个也要剪枝避免无效运算导致的超时 func combinationSum2(candidates []int, target int) [][]int {// 代码二刷sort.Ints(candidates)history : make([]bool, len(candidates))list : make([]int, 0)res : make([][]int, 0)backtrack(res, list,candidates,target,0,0,history)return res } func backtrack(res *[][]int, list, candidates []int, target, index, sum int,history []bool) {if sum target {ans : make([]int, len(list))copy(ans, list)*res append(*res, ans)return} else if sum target {return}for i:index; ilen(candidates); i {if i1 candidates[i] candidates[i-1] history[i-1] false {continue}sum candidates[i]list append(list, candidates[i])history[i] truebacktrack(res, list, candidates, target, i1, sum,history)sum - candidates[i]list list[:len(list)-1]history[i] false} }3、131. 分割回文串 题目 给你一个字符串 s请你将 s 分割成一些子串使每个子串都是 回文串 。返回 s 所有可能的分割方案。 回文串 是正着读和反着读都一样的字符串。 输入s “aab” 输出[[“a”,“a”,“b”],[“aa”,“b”]] 思路 细节注意i:index注意其实回文很简单带入例子就明白了*res append(*res, ans)注意是 ans为什么呢 func partition(s string) [][]string {// 代码二刷条件就是判断是否为回文字符串list : make([]string, 0)res : make([][]string, 0)backtrack(res, list, s, 0)return res } func backtrack(res *[][]string, list []string, s string, index int) {if index len(s) {ans : make([]string, len(list))copy(ans, list)*res append(*res, ans)return}for i:index; ilen(s); i {if huiwen(s, index, i) {list append(list, s[index:i1])backtrack(res, list, s, i1)list list[:len(list)-1]}} } func huiwen(s string, left,right int) bool {for leftright {if s[left] ! s[right] {return false}leftright--}return true }
http://www.zqtcl.cn/news/379890/

相关文章:

  • 宁波网站建设 联系哪家电子商务网站建设过程范文
  • 南宁商城网站建设网站建设的需求文档
  • dedeampz 部署wordpress 网站访问慢如何评价网站是否做的好处
  • 怎样建设个人影视网站设计学专业
  • 没有公司 接单做网站网站建设加盟合作
  • 如何将域名和网站绑定做网站找投资人
  • 网站开发 平台WordPress首页可见
  • 沧州做网站费用打开上海发布
  • 重庆潼南网站建设公司电话网站能调用一些字体
  • 摄影网站设计素材做彩票网站电话多少
  • 开网站公司企业管理网课
  • 相城高端网站建设施工建设集团网站
  • .电子商务网站的开发原则包括网络服务示范区创建情况
  • 网站如何做权重php做网站登陆验证
  • 昆山制造网站的地方网站建设 有聊天工具的吗
  • 自己做网站制作需要多少钱如何免费注册网站域名
  • 如何做网站美化怎样写网站文案
  • 做网站排名的wordpress 调整 行距
  • 三亚文明城市建设服务中心报名网站房地产活动策划网站
  • 休闲食品网站建设规划书常德做网站专业公司
  • 做美工好的网站网页设计排版布局
  • 网站建设公司合同模板下载wordpress微信公众平台开发教程
  • 快速wordpress 建网站免费代理游戏
  • 网站模板 寻模板大气宽屏网站模板企业源码带后台
  • 做图片推广的网站威海高端网站建设
  • 台州网站公司建站网站首页模板图片
  • 网站建设本科毕业设计论文网址
  • 泰州企业建站程序乐清网站建设公司
  • 微信小程序网站建设哪家好郑州建设网
  • 网站流量查询站长之家自己创业做原公司一样的网站