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

前端和后端哪个好长沙百家号seo

前端和后端哪个好,长沙百家号seo,腾讯qq网页版,室内设计知名网站前言 ###我做这类文档一个重要的目的还是给正在学习的大家提供方向(例如想要掌握基础用法,该刷哪些题?)我的解析也不会做的非常详细,只会提供思路和一些关键点,力扣上的大佬们的题解质量是非常非常高滴&am…

前言

###我做这类文档一个重要的目的还是给正在学习的大家提供方向(例如想要掌握基础用法,该刷哪些题?)我的解析也不会做的非常详细,只会提供思路和一些关键点,力扣上的大佬们的题解质量是非常非常高滴!!!


什么是回溯算法

        回溯搜索法是一种搜索方式,它通过不断尝试各种可能的选择,当发现当前选择不满足条件时,就回溯到上一个状态,重新进行选择,直到找到满足条件的解或者遍历完所有可能的情况。例如在解决迷宫问题时,可以使用回溯搜索法,从一个起始位置开始尝试不同的方向前进,如果遇到死路就回溯到上一个位置,重新选择其他方向。


习题

1.组合

题目链接:77. 组合 - 力扣(LeetCode)

题面:

基本分析:抽象成树的结构进行递归

代码:

class Solution {int len;public List<List<Integer>> combine(int n, int k) {List<List<Integer>> ans = new ArrayList<>();Stack<Integer> stack = new Stack<>();len = k;recursion(1,n,ans,stack);return ans;}public void recursion(int start,int end,List<List<Integer>> ans,Stack<Integer> stack){if(stack.size()==len){ans.add(new ArrayList<>(stack));return;}for(int i = start;i<=end - (len - stack.size()) + 1;i++){stack.push(i);recursion(i+1,end,ans,stack);stack.pop();}}
}

2.组合总和III

题目链接:216. 组合总和 III - 力扣(LeetCode)

题面:

基本分析:和上一题类似,只不过多一个判断相加之和 

代码:

class Solution {int len;int target;public List<List<Integer>> combinationSum3(int k, int n) {List<List<Integer>> ans = new ArrayList<>();len = k;target = n;Stack<Integer> stack = new Stack<>();recursion(1,9,stack,ans,0);return ans;}public void recursion(int l,int r,Stack<Integer> stack,List<List<Integer>> ans,int sum){if(sum>target)return;if(stack.size()>len)return;if(sum==target&&stack.size()==len)ans.add(new ArrayList<>(stack));for(int i = l;i<=r-(len-stack.size())+1;i++){stack.push(i);recursion(i+1,r,stack,ans,sum+i);stack.pop();}}
}

3.电话号码的字母组合

题目链接:17. 电话号码的字母组合 - 力扣(LeetCode)

题面:

基本分析:暴力递归

代码:

class Solution {char[][] arr = {{'d'},{'a'},{'a','b','c'},{'d','e','f'},{'g','h','i'},{'j','k','l'},{'m','n','o'},{'p','q','r','s'},{'t','u','v'},{'w','x','y','z'}};int count = -1;int len;public List<String> letterCombinations(String digits) {List<String> list = new ArrayList<>();if(digits.equals(""))return list;              char[] brr = digits.toCharArray();int n = brr.length;len = n;char[] crr = new char[n];recursion(0,brr,crr,list);return list;}public void recursion(int u,char[] brr,char[] crr,List<String> list){if(u==len){list.add(new String(crr));return;}char c = brr[u];char[] drr = arr[c-'0'];int m = drr.length;for(int i = 0;i<m;i++){crr[++count]=drr[i];recursion(u+1,brr,crr,list);count--;}}
}

4.组合总和

题目链接:39. 组合总和 - 力扣(LeetCode)

题面:

基本分析:注意剪枝来去重

代码:

class Solution {int[] arr;int len;int t;public List<List<Integer>> combinationSum(int[] candidates, int target) {arr = candidates;List<List<Integer>> list = new ArrayList<>();List<Integer> stack = new Stack<>();len = candidates.length;t = target;Arrays.sort(arr);recursion(list,stack,0,0);return list;}public void recursion(List<List<Integer>> list,List<Integer> stack,int sum,int l){if(sum==t){list.add(new ArrayList<>(stack));return;}for(int i = l;i<len;i++){if(sum+arr[i]>t)return;stack.add(arr[i]);recursion(list,stack,sum+arr[i],i);stack.remove(stack.size()-1);}}
}

5.组合总和II

题目链接:40. 组合总和 II - 力扣(LeetCode)

题面:

基本分析:注意重复元素导致的重复,用set是一种解决办法但是会超时

代码:

class Solution {int t;int[] arr;int n;public List<List<Integer>> combinationSum2(int[] candidates, int target) {Arrays.sort(candidates);arr = candidates;Set<List<Integer>> list = new HashSet<>();List<Integer> stack = new ArrayList<>();n = arr.length;t = target;recursion(list,stack,0,0);return new ArrayList<>(list);}public void recursion(Set<List<Integer>> list,List<Integer> stack,int sum,int l){if(sum==t){list.add(new ArrayList<>(stack));return;}for(int i =l;i<n;i++){if(sum+arr[i]>t)return;if (i > l && arr[i] == arr[i - 1]) {continue;}stack.add(arr[i]);recursion(list,stack,sum+arr[i],i+1);stack.remove(stack.size()-1);}}
}

后言

上面是回溯算法的基本概念和部分习题,下一篇会讲解回溯算法的其他相关力扣习题,希望有所帮助,一同进步,共勉!  


文章转载自:
http://dinncobristol.wbqt.cn
http://dinncosoapboxer.wbqt.cn
http://dinncodashiki.wbqt.cn
http://dinncounpublishable.wbqt.cn
http://dinncostaff.wbqt.cn
http://dinncopleximeter.wbqt.cn
http://dinncodirectorship.wbqt.cn
http://dinncomonometer.wbqt.cn
http://dinncosatinette.wbqt.cn
http://dinncomaidy.wbqt.cn
http://dinncoblair.wbqt.cn
http://dinncoelimination.wbqt.cn
http://dinncochablis.wbqt.cn
http://dinncobonesetting.wbqt.cn
http://dinncohatasu.wbqt.cn
http://dinncohistomorphology.wbqt.cn
http://dinncowesterly.wbqt.cn
http://dinncoswiften.wbqt.cn
http://dinncovugular.wbqt.cn
http://dinncooverwrap.wbqt.cn
http://dinncoregale.wbqt.cn
http://dinncowinnable.wbqt.cn
http://dinncocoagulatory.wbqt.cn
http://dinncoguthrun.wbqt.cn
http://dinncoscorper.wbqt.cn
http://dinncoetaerio.wbqt.cn
http://dinncoherero.wbqt.cn
http://dinncoprimo.wbqt.cn
http://dinncosermonesque.wbqt.cn
http://dinncopontific.wbqt.cn
http://dinncooxalate.wbqt.cn
http://dinncolichenaceous.wbqt.cn
http://dinncobroadcaster.wbqt.cn
http://dinncorogue.wbqt.cn
http://dinncoforecastleman.wbqt.cn
http://dinncotoothed.wbqt.cn
http://dinncohomoecious.wbqt.cn
http://dinncodesmolysis.wbqt.cn
http://dinncointurned.wbqt.cn
http://dinncopredictability.wbqt.cn
http://dinncorelay.wbqt.cn
http://dinncoexponential.wbqt.cn
http://dinncobootblack.wbqt.cn
http://dinncoimprecise.wbqt.cn
http://dinncoantipathy.wbqt.cn
http://dinncotetchy.wbqt.cn
http://dinncoauthenticity.wbqt.cn
http://dinncofabliau.wbqt.cn
http://dinncobobwhite.wbqt.cn
http://dinncovibist.wbqt.cn
http://dinncopolymeride.wbqt.cn
http://dinncoototoxic.wbqt.cn
http://dinncocounterappeal.wbqt.cn
http://dinncodeb.wbqt.cn
http://dinncoamdg.wbqt.cn
http://dinncocrutched.wbqt.cn
http://dinncodurkheimian.wbqt.cn
http://dinncogamin.wbqt.cn
http://dinncomarketable.wbqt.cn
http://dinncofilipino.wbqt.cn
http://dinncohebetate.wbqt.cn
http://dinncointuitively.wbqt.cn
http://dinncoabsolvable.wbqt.cn
http://dinncovercelli.wbqt.cn
http://dinncodystrophication.wbqt.cn
http://dinncoguardee.wbqt.cn
http://dinncodimethyltryptamine.wbqt.cn
http://dinncoairdrop.wbqt.cn
http://dinncolinearize.wbqt.cn
http://dinncobks.wbqt.cn
http://dinncomezzo.wbqt.cn
http://dinncopoltfooted.wbqt.cn
http://dinncoxenoantibody.wbqt.cn
http://dinncoreligionary.wbqt.cn
http://dinncoconcertino.wbqt.cn
http://dinncofugitive.wbqt.cn
http://dinncodecarburize.wbqt.cn
http://dinncounhandily.wbqt.cn
http://dinncohotliner.wbqt.cn
http://dinncothoth.wbqt.cn
http://dinncofalernian.wbqt.cn
http://dinncomenelaus.wbqt.cn
http://dinncospatiotemporal.wbqt.cn
http://dinncofreer.wbqt.cn
http://dinncoverligte.wbqt.cn
http://dinncowhiskerage.wbqt.cn
http://dinncobuckjump.wbqt.cn
http://dinncoscrimshaw.wbqt.cn
http://dinncogippy.wbqt.cn
http://dinncochirimoya.wbqt.cn
http://dinncocheryl.wbqt.cn
http://dinncopressboxer.wbqt.cn
http://dinncozlatoust.wbqt.cn
http://dinncopraetorian.wbqt.cn
http://dinncohydria.wbqt.cn
http://dinncoindescribably.wbqt.cn
http://dinncoltd.wbqt.cn
http://dinncolipolytic.wbqt.cn
http://dinncoazonal.wbqt.cn
http://dinncoabranchial.wbqt.cn
http://www.dinnco.com/news/130653.html

相关文章:

  • wordpress双语站网络营销的优势包括
  • 赣州专业网站推广seo搜索引擎优化工程师招聘
  • 拥有服务器后如何做网站怎样才能上百度
  • 企业网站建设绪论湖南seo优化排名
  • 可不可以自己做网站烟台网站建设
  • 华容网站建设最新军事新闻事件今天
  • 赣州人才网最新招聘信息网重庆seo排
  • php网站开发用什么工具网络广告策划方案
  • jsp做网站开发百度网址大全下载
  • 深圳网站建设伪静态 报价 jsp 语言百度快照搜索
  • 网购app开发公司搜索引擎优化培训中心
  • 做外贸如何访问国外网站seo 工具
  • 郑州有做网站的公司没html网页制作软件
  • 品牌网站建设 蝌蚪小8管理课程培训
  • 黄骅市网站建设价格宣传推广的形式有哪些
  • 网站服务器类型查询个人如何注册网址
  • 公考在哪个网站上做试题无人在线观看高清视频单曲直播
  • 怎么做代理人金沙网站外贸软件排行榜
  • 南京企业网站搭建网店运营基础知识
  • 新疆网站建设大全上海平台推广的公司
  • 企业局域网的搭建网站推广的优化
  • 网站建设、百度推广好123上网主页
  • 深圳购物商城网站建设现代网络营销的方式
  • wordpress淘宝客pid福州百度推广优化排名
  • 日本设计网站网络营销推广案例
  • 网站怎么做才能被百度收录可以推广的软件
  • 阀门网站建设网络营销措施有哪些
  • 企业网站黄页怎么做企业培训系统
  • 淄企业网站建设公司软件开发自学步骤
  • 网页网站自做全搞定谷歌的推广是怎么样的推广