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

建零售网站还是装修风格有哪些

建零售网站还是,装修风格有哪些,wordpress 2m,网站关键词如何做竞价文章目录 39.组合总和40.组合总和II131.分割回文串 39.组合总和 文字讲解&#xff1a;组合总和 视频讲解&#xff1a;组合总和 状态: 此题ok 思路&#xff1a; 代码&#xff1a; class Solution {int sum;public List<List<Integer>> combinationSum(int[] candi…

文章目录

    • 39.组合总和
    • 40.组合总和II
    • 131.分割回文串

39.组合总和

文字讲解:组合总和

视频讲解:组合总和

状态: 此题ok

思路:

代码:

class Solution {int sum;public List<List<Integer>> combinationSum(int[] candidates, int target) {List<List<Integer>> result = new ArrayList<>();LinkedList<Integer> tempList = new LinkedList<>();backTracking(result, tempList, candidates, 0, target);return result;}public void backTracking(List<List<Integer>> result, LinkedList<Integer> tempList, int[] candidates, int startIndex, int target) {if (!tempList.isEmpty()&&sum>target) {return;}if (!tempList.isEmpty() && sum==target) { //收集List<Integer> resultParam = new ArrayList<>(tempList);result.add(resultParam);return;}for (int i = startIndex; i < candidates.length; i++) {tempList.offer(candidates[i]);sum+=candidates[i];backTracking(result, tempList, candidates, i, target);tempList.pollLast();sum-=candidates[i];}}
}

40.组合总和II

文字讲解:组合总和II

视频讲解:组合总和II

状态:这题一开始想先排序后去重,再做回溯;想岔批了,应该要保证前后处理相同元素的时候,要进行跳过来进行去重;

思路:

1、这一题,注意枝剪操作,即sum + candidates[i] <= target;不然提交leetcode会超时;

代码:

class Solution {int sum;public List<List<Integer>> combinationSum2(int[] candidates, int target) {List<List<Integer>> result = new ArrayList<>();LinkedList<Integer> tempList = new LinkedList<>();Arrays.sort(candidates);//完成去重backTracking(result, tempList, candidates, 0, target);return result;}public void backTracking(List<List<Integer>> result, LinkedList<Integer> tempList, int[] candidates, int startIndex, int target) {if (!tempList.isEmpty()&&sum==target) {List<Integer> resultParam = new ArrayList<>(tempList);result.add(resultParam);return;}for (int i = startIndex; i < candidates.length && sum + candidates[i] <= target; i++) {if (i>startIndex && candidates[i]==candidates[i-1]) {continue;}tempList.offer(candidates[i]);sum+=candidates[i];backTracking(result, tempList, candidates, i+1, target);tempList.pollLast();sum-=candidates[i];}}
}

131.分割回文串

文字讲解:分割回文串

视频讲解:分割回文串

状态:这题细细一想,和前两题也是类似换汤不换药,看来还是对回溯-排列问题理解不够透彻;

思路:

代码:

class Solution {List<List<String>> result = new ArrayList<>();LinkedList<String> tempList = new LinkedList<>();public List<List<String>> partition(String s) {backTracking(s, 0);return result;}public void backTracking(String s, int startIndex) {if (startIndex>=s.length()) {List<String> resultParam = new ArrayList<>(tempList);result.add(resultParam);return;}for (int i = startIndex; i < s.length(); i++) {if(isPalindrome(s, startIndex, i)) {tempList.offer(s.substring(startIndex, i+1));} else {continue;}backTracking(s, i+1);tempList.pollLast();}}public boolean isPalindrome(String s, int start, int end) {while (start<=end) {if (s.charAt(start) == s.charAt(end)) {start++;end--;} else {return false;}}return true;}
}
http://www.yayakq.cn/news/357497/

相关文章:

  • 平面设计怎么接单seo搜索工具栏
  • 香河住房与建设局网站金融网站模板源代码
  • 寮步网站建设公司学做视频t的网站
  • 中山哪里有好网站建设公司自己做视频网站上传视频
  • 简单网站建设模板曹鹏wordpress教程 下载
  • 简单的网站开发模板外国网站 游戏设定图
  • 重庆农村网站建设13572074638网站建设
  • 做网站的要多钱龙岩做网站价格
  • 怎样使用二维码做网站2019个人建网站
  • 网站建设的网seo优化快速排名
  • 张家港网站建设培训太原建设银行网站
  • 网站首页页面代码网站应用软件怎么架设
  • 软件开发者平台有哪些宁波seo服务
  • 汉堡只做网站做网站开发有哪些优点呢
  • 网站建设 中企动力扬州网络广告是较为常见的一种网络营销方式
  • 陕西省建设银行网站6wordpress 相册模板
  • 南京网站制作设计公司智慧软文发稿平台官网
  • 长沙公司网站设计报价成都 网站
  • 网站建设学多长时间湖南湘潭网站建设
  • 免费的个人网站怎么做促销策略的四种方式
  • 郑州恩恩网站建设外包服务是什么意思
  • 给菠菜网站做外包php开源订单管理系统
  • 建设网站二级建造师如何解聘提供邵阳网站建设
  • 淘宝做网站推广人电话服务外包
  • 常德网站建设套餐报价类似于wordpress的网站吗
  • 营销型企业网站建设的步骤建筑工程公司简介模板范文
  • 网站模板在线演示怎么做王也王志飞
  • 个人定制网站怎么做购物网站开发设计思路
  • 北京知名互联网公司排名青岛网站seo公司
  • 大型门户网站建设多少钱男女做爰网站