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

烟台网站优化公司自己制作的网站怎么做分页

烟台网站优化公司,自己制作的网站怎么做分页,wordpress添加商品分类页,漯河做网站优化组合总和 问题描述 给你一个 无重复元素 的整数数组 candidates 和一个目标整数 target ,找出 candidates 中可以使数字和为目标数 target 的 所有 不同组合 ,并以列表形式返回。你可以按 任意顺序 返回这些组合。candidates 中的 同一个 数字可以 无限…

组合总和

问题描述

给你一个 无重复元素 的整数数组 candidates 和一个目标整数 target ,找出 candidates 中可以使数字和为目标数 target 的 所有 不同组合 ,并以列表形式返回。你可以按 任意顺序 返回这些组合。candidates 中的 同一个 数字可以 无限制重复被选取 。如果至少一个数字的被选数量不同,则两种组合是不同的。 对于给定的输入,保证和为 target 的不同组合数少于 150 个。详见leetcode39

问题分析

我们可以从candidates[0]开始,不断选取candidates[0],直至target-candidates[0]<=0,如果等于0,则我们得到一个满足条件的组合,否则回退一步,去掉一个candidates[0],添加一个candidates[1],如此不断进行下去,满足局部枚举➕递归+放下前任,我门可以使用回溯模板来解决。

代码实现

public List<List<Integer>> combinationSum(int[] candidates, int target) {List<Integer> numList = new ArrayList<>();List<List<Integer>> resultList = new ArrayList();combinationSum(candidates,target,0,numList,resultList);return resultList;
}public void combinationSum(int[] candidates, int target,int index,List<Integer> numList,List<List<Integer>> resultList){if(target<0){return;}if(target==0){resultList.add(new ArrayList<>(numList));return;}for(int i=index;i<candidates.length;i++){numList.add(candidates[i]);combinationSum(candidates,target-candidates[i],i,numList,resultList);numList.remove(numList.size()-1);}
}

全排列

问题描述

给定一个不含重复数字的数组 nums ,返回其 所有可能的全排列 。你可以 按任意顺序 返回答案。

问题分析

排列与组合类似,只是重复元素可以按照不同顺序成为不同的排列,我们不再是按顺序的取,而是定义一个used数组判断给定数组的元素是否被使用。当我们的排列结果中的元素与给定数组个数相同时,即得到一个排列,添加到结果数组中。

代码实现

public List<List<Integer>> permute(int[] nums) {List<List<Integer>> res = new ArrayList<>();LinkedList<Integer> ans = new LinkedList<>();boolean[] used = new boolean[nums.length];permute(res,ans,used,nums);return res;
}
public void permute(List<List<Integer>> res,LinkedList<Integer> ans,boolean[] used,int[] nums){if(ans.size()==nums.length){res.add(new ArrayList<>(ans));return;}for(int i=0;i<nums.length;i++){if(used[i]){continue;}used[i] = true;ans.add(nums[i]);permute(res,ans,used,nums);ans.removeLast();used[i] = false;}
}
http://www.yayakq.cn/news/703928/

相关文章:

  • 大兴网站开发公司大型门户网站源码
  • 长春建站公司网站压缩wordpress空间
  • 无锡网站建站公司wordpress下载中
  • 建设网站的价格怎样免费建立自己的网站
  • php网站开发 远程平乡网站建设
  • 做网站可以卖别的牌子的产品吗可口可乐软文范例
  • 影响网站收录的因素菏泽做网站的
  • 网站建设及维护业务服务合同玉林做网站优化推广
  • 网站如何制作注册上海广告传媒有限公司
  • ps做的网站模板网站建设 维护 编程
  • 做商务网站网站页脚包括什么
  • 建设一个网站需要什么技术指标wordpress lamp lnmp
  • 公司建设网站带来什么大通拓客软件官网
  • 站长之家排行榜怎么在word上做超链接网站
  • 德州做网站最好的公司国内外贸平台有哪些
  • 买公司 网站建设制作一个小型网站
  • 请别人做网站如何交付未来最吃香的十大行业2022
  • 浙江昆仑建设集团网站上海房产信息网官网
  • 网站建设标准流程及外包注意事项百度广州分公司
  • seo神马网站推广器frontpage制作网页的软件
  • 通过招聘网站如何做背景调查自适应网站案例
  • 装修网站建设服务商义乌个人兼职做建设网站
  • 备案的网站是公司吗湖南省住房和城乡建设网站
  • 网站的动态文字是怎么做的如何在各网站做推广
  • 优秀企业网站有哪些江苏省建设厅网站官网
  • html5炫酷的网站wordpress在哪设置评论
  • 月付购物网站建站深圳网站制作十年乐云seo品牌
  • wp系统网站如何做seopc网站模板
  • 网站建设基本概述网站建设那个好
  • 怎么学网站开发项目网址大全