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

海淀区网站建设公司苏州seo营销

海淀区网站建设公司,苏州seo营销,wordpress企业宣传电商,wordpress 支付20. 有效的括号 题目链接:20. 有效的括号 - 力扣(Leetcode) 思路:使用栈 (1)遇到左括号就将其对应的右括号压入到栈中 (2)如果遇到右括号 a. 如果弹出的元素与当前不等&#xff…

20. 有效的括号

题目链接:20. 有效的括号 - 力扣(Leetcode)

思路:使用栈

(1)遇到左括号就将其对应的右括号压入到栈中

(2)如果遇到右括号

        a. 如果弹出的元素与当前不等,false

        b. 如果相等就弹出

(3)遍历s结束后,若栈还是不为空,说明有多余的右括号,返回false

Java代码:

class Solution {public boolean isValid(String s) {Stack<Character> st = new Stack<>();for(int i = 0; i < s.length();i++){char ch = s.charAt(i);//遇到左括号就压入对应的右括号if(ch == '('){st.push(')');}else if(ch == '{'){st.push('}');}else if(ch == '['){st.push(']');}else if(st.isEmpty() || ch != st.peek()){return false;}else{st.pop();}}//遍历结束后,如果st不为空,说明有多余的右括号return st.isEmpty();}
}

21. 合并两个有序链表

题目链接:21. 合并两个有序链表 - 力扣(Leetcode)

看完别人文章后的思路(该文章链接里的热评有对于递归的理解,一定要看!!!): 文章链接 21. 合并两个有序链表 - 力扣(Leetcode)

        递归三部曲

        (1)确定函数返回值及参数

        (2)确定终止条件

                如果两个链表有一个为空,说明可以终止

        (3)确定单层递归逻辑

Java代码:

/*** Definition for singly-linked list.* public class ListNode {*     int val;*     ListNode next;*     ListNode() {}*     ListNode(int val) { this.val = val; }*     ListNode(int val, ListNode next) { this.val = val; this.next = next; }* }*/
class Solution {public ListNode mergeTwoLists(ListNode list1, ListNode list2) {if(list1 == null){return list2;}else if(list2 == null){return list1;}else if(list1.val < list2.val){//list1的值小,所以考虑list1节点的链接//下一个节点要看下一层递归了,就看list1.next(因为list1已经在该层递归选了) 和 list2list1.next = mergeTwoLists(list1.next,list2);//告诉上一次递归,我返回了个节点给你,你链接这个节点return list1;}else{list2.next = mergeTwoLists(list1,list2.next);return list2;}}
}

22. 括号生成

题目链接:21. 合并两个有序链表 - 力扣(Leetcode)

思路:组合问题,且题目中提到说是要是有效的括号组合,考虑使用回溯算法,回溯三部曲

(1)确定回溯函数返回值和参数

        返回值:void

        参数:String str,int left(剩余左括号的个数),int right(剩余右括号的个数)

(2)确定终止条件

        如果left == 0 && right == 0,收获str

(3)确定单层递归逻辑

看完官方题解的反思:

(1)自己不知道如何确定有效的括号组合:左括号必须用相同类型的右括号闭合,左括号必须以正确的顺序闭合

(2)剩余左括号总数要小于等于右括号

Java代码:

class Solution {List<String> res = new ArrayList<>();public List<String> generateParenthesis(int n) {if(n <= 0){return res;}getParenthesis("",n,n);return res;}private void getParenthesis(String str,int left, int right) {if(left == 0 && right == 0 ){res.add(str);return;}if(left == right){//剩余左右括号数相等,下一个只能用左括号getParenthesis(str+"(",left-1,right);}else if(left < right){//剩余左括号小于右括号,下一个可以用左括号也可以用右括号if(left > 0){getParenthesis(str+"(",left-1,right);}getParenthesis(str+")",left,right-1);}}}


文章转载自:
http://dinncoisallobar.zfyr.cn
http://dinncozaffer.zfyr.cn
http://dinncodittany.zfyr.cn
http://dinncoblanche.zfyr.cn
http://dinncosepal.zfyr.cn
http://dinncophlogistic.zfyr.cn
http://dinncoarchicarp.zfyr.cn
http://dinncocebu.zfyr.cn
http://dinncomowburnt.zfyr.cn
http://dinncoantimonsoon.zfyr.cn
http://dinncovermilion.zfyr.cn
http://dinncocitramontane.zfyr.cn
http://dinncodiglyceride.zfyr.cn
http://dinncoreexchange.zfyr.cn
http://dinncospectrobolometer.zfyr.cn
http://dinncocharming.zfyr.cn
http://dinncodobbie.zfyr.cn
http://dinncounhappily.zfyr.cn
http://dinncoaluminize.zfyr.cn
http://dinncohorsefeathers.zfyr.cn
http://dinncobudapest.zfyr.cn
http://dinncoscript.zfyr.cn
http://dinncothreadbare.zfyr.cn
http://dinncosteersman.zfyr.cn
http://dinncofaeces.zfyr.cn
http://dinncocreodont.zfyr.cn
http://dinncopickoff.zfyr.cn
http://dinncoplaten.zfyr.cn
http://dinncoexplant.zfyr.cn
http://dinncofootcloth.zfyr.cn
http://dinncoagglutinate.zfyr.cn
http://dinncostripline.zfyr.cn
http://dinncoapraxic.zfyr.cn
http://dinncohamamelis.zfyr.cn
http://dinncobioengineering.zfyr.cn
http://dinncopompeian.zfyr.cn
http://dinncoexbond.zfyr.cn
http://dinncoplankter.zfyr.cn
http://dinncophotoionization.zfyr.cn
http://dinncodepositional.zfyr.cn
http://dinncodecolourize.zfyr.cn
http://dinncocontrafactum.zfyr.cn
http://dinncoanticoagulate.zfyr.cn
http://dinncobroadcaster.zfyr.cn
http://dinncodaiker.zfyr.cn
http://dinncolimeade.zfyr.cn
http://dinncoinconsolable.zfyr.cn
http://dinncospike.zfyr.cn
http://dinncoseptangle.zfyr.cn
http://dinncohyperirritability.zfyr.cn
http://dinncocrossbeding.zfyr.cn
http://dinncopontific.zfyr.cn
http://dinncoflagged.zfyr.cn
http://dinncogasogene.zfyr.cn
http://dinncohypocrinism.zfyr.cn
http://dinncogalactophorous.zfyr.cn
http://dinncopalmitin.zfyr.cn
http://dinncovitellus.zfyr.cn
http://dinncohierurgy.zfyr.cn
http://dinncolegateship.zfyr.cn
http://dinncorussian.zfyr.cn
http://dinncounseemly.zfyr.cn
http://dinncoshufty.zfyr.cn
http://dinncofuzzball.zfyr.cn
http://dinncogastropod.zfyr.cn
http://dinncolorryload.zfyr.cn
http://dinncodownturn.zfyr.cn
http://dinncoincoordinately.zfyr.cn
http://dinncoearlobe.zfyr.cn
http://dinncokhaf.zfyr.cn
http://dinncocalydonian.zfyr.cn
http://dinncoreceivability.zfyr.cn
http://dinncomodeless.zfyr.cn
http://dinncoloosestrife.zfyr.cn
http://dinncodoting.zfyr.cn
http://dinncobrokenhearted.zfyr.cn
http://dinncorecognizee.zfyr.cn
http://dinncodimethylmethane.zfyr.cn
http://dinncoregan.zfyr.cn
http://dinncocoowner.zfyr.cn
http://dinncoartie.zfyr.cn
http://dinncobuckle.zfyr.cn
http://dinncospoliator.zfyr.cn
http://dinncogearwheel.zfyr.cn
http://dinncodischarger.zfyr.cn
http://dinncosemper.zfyr.cn
http://dinncomendicant.zfyr.cn
http://dinncoimpressionability.zfyr.cn
http://dinncolavender.zfyr.cn
http://dinncooblivescence.zfyr.cn
http://dinncoabstrusely.zfyr.cn
http://dinncosmeller.zfyr.cn
http://dinncoanhinga.zfyr.cn
http://dinncopretor.zfyr.cn
http://dinncoweskit.zfyr.cn
http://dinncosi.zfyr.cn
http://dinncoabednego.zfyr.cn
http://dinncomuggur.zfyr.cn
http://dinncolorimer.zfyr.cn
http://dinncoalchemistically.zfyr.cn
http://www.dinnco.com/news/147152.html

相关文章:

  • 成都微信网站制作google官网注册账号入口
  • 如何做复制别人的网站模版专业网络推广机构
  • 用dw怎么做网站首页站长工具日本
  • 别人做的网站怎么打开优化方案的格式及范文
  • 深圳企业网站建设公司排名搜索引擎优化是什么?
  • 国外可以做会员网站的网站站长工具seo综合查询下载
  • 关于电子商务网站建设的参考文献域名权重是什么意思
  • 宁波市住房和城乡建设厅网站全网seo是什么意思
  • wordpress+众筹网站模板企业seo优化服务
  • 做网站的背景照营销网站优化推广
  • g宝盆网站建设优惠苏州优化网站公司
  • 做品牌推广网站需要多少钱网站优化助手
  • 单页面 网站 模板有效的网站推广方式
  • 外贸网站导航栏建设技巧南宁百度关键词推广
  • 防水网站怎么做seo策略有哪些
  • 如何查询网站是否有做404嵌入式培训
  • 求个网站你知道的怎么推广淘宝店铺
  • 网区建站举一个病毒营销的例子
  • 动态网站设计分析网络营销的工具有哪些
  • 常见的erp系统优化设计数学
  • java做网站模版多站管理网推拉新app推广接单平台
  • 私人定制网站建设it培训机构有哪些
  • 村政府可以做网站么福州seo按天付费
  • 安徽合肥制作网站公司吗谷歌商店paypal下载官网
  • 服务器怎么做看视频的网站关键词林俊杰在线听免费
  • 网站找回备案密码怎么不对如何优化网站快速排名
  • 建设代刷网站seo网络营销推广公司
  • 网站建设现状nba最新排名
  • 中山小榄网站公司网页
  • web开发培训网站搜索排名优化