当前位置: 首页 > news >正文 室内设计师灵感网站企业管理咨询合同书范本 news 2025/10/31 7:09:36 室内设计师灵感网站,企业管理咨询合同书范本,高端网站建设的公司哪家好,网站怎么优化 优帮云leetcode20.括号匹配问题 前言#xff1a; #x1f4a5;#x1f388;个人主页:Dream_Chaser#xff5e; #x1f388;#x1f4a5; ✨✨刷题专栏:http://t.csdn.cn/UlvTc ⛳⛳本篇内容:力扣上栈与队列的面试OJ题目 目录 leetcode20.括号匹配问题 1.问题描…leetcode20.括号匹配问题 前言 个人主页:Dream_Chaser ✨✨刷题专栏:http://t.csdn.cn/UlvTc ⛳⛳本篇内容:力扣上栈与队列的面试OJ题目 目录 leetcode20.括号匹配问题 1.问题描述 2.前提准备 3.问题题解 1.问题描述 给定一个只包括 (){}[] 的字符串 s 判断字符串是否有效。 有效字符串需满足 左括号必须用相同类型的右括号闭合。左括号必须以正确的顺序闭合。每个右括号都有一个对应的相同类型的左括号。 2.前提准备 栈的实现 #pragma once #includestdlib.h #includeassert.h #includestdbool.h #includestdio.h typedef int STDataType; typedef struct Stack {STDataType* a;int top;//栈顶的位置int capacity;//栈的容量 }ST;void STInit(ST* pst); void STDestroy(ST* pst); void STPush(ST* pst,STDataType x); void STPop(ST* pst); STDataType STTop(ST* pst); bool STEmpty(ST* pst); int STSize(ST*pst);void STInit(ST* pst) {assert(pst);pst-a NULL;//栈底//top不是下标pst-top 0;//指向栈顶元素的下一个位置pst-capacity 0;} void STDestroy(ST* pst) {assert(pst);free(pst-a);pst-a NULL; }void STPush(ST* pst,STDataType x) {if (pst-top pst-capacity){int newCapacity pst-capacity 0 ? 4 : pst-capacity * 2;STDataType* tmp (STDataType*)realloc(pst-a, newCapacity * sizeof(STDataType));if (tmp NULL){perror(realloc fail);return;}pst-a tmp;//返回的是realloc出来的内存块的地址pst-capacity newCapacity;//把扩容后的空间大小赋值给栈容量}pst-a[pst-top] x;//先放值pst-top;//再 }void STPop(ST* pst) {assert(pst);assert(!STEmpty(pst));pst-top--; }STDataType STTop(ST* pst) {assert(pst);assert(!STEmpty(pst));return pst-a[pst-top - 1]; }bool STEmpty(ST* pst)//栈为空返回true,不为空返回false {//assert(pst);//if (pst-top 0)//{// return true;//}//else//{// return false;//}return pst-top 0; }int STSize(ST* pst) {assert(pst);return pst-top; } 3.问题题解 s指向的是右括号,top存储的是左括号st栈顶指针a栈底指针 只要有一次不对应的情况那么程序直接返回false字符串遍历结束若栈不为空直接返回false在比较过程中若遇到栈为空可是此时字符串未遍历完直接返回false 第一种情况:左括号多余 第二种情况:括号没有多余但是类型匹配不上 第三种情况:右括号多余 代码实现 bool isValid(char * s){ST st;STInit(st);while(*s)//*s就是输入的那个x的值{//1.左括号入栈if(*s ( || *s [ || *s {){STPush(st, *s); }else{if(STEmpty(st))//栈为空也需要销毁因为它malloc了空间空间在那占用着只是数据没填进去{STDestroy(st);return false;}//右括号出栈匹配char topSTTop(st);STPop(st);//只要有一个不匹配直接返回false//左括号和右括号相等说明不了问题只能说明这一次这一对括号匹配还有其它括号不匹配的//所以要找到不继续的条件if((*s ] top! [)||(*s ) top !()||(*s} top!{)){STDestroy(st);return false;}}s;//字符指针的移动}bool retSTEmpty(st);//栈不为空那就是falseSTDestroy(st);return ret; } 代码执行 本文结束若有错误欢迎改正谢谢支持 文章转载自: http://www.morning.fnkcg.cn.gov.cn.fnkcg.cn http://www.morning.wjxyg.cn.gov.cn.wjxyg.cn http://www.morning.kgqpx.cn.gov.cn.kgqpx.cn http://www.morning.lsbjj.cn.gov.cn.lsbjj.cn http://www.morning.brbmf.cn.gov.cn.brbmf.cn http://www.morning.sbrxm.cn.gov.cn.sbrxm.cn http://www.morning.sbrxm.cn.gov.cn.sbrxm.cn http://www.morning.jcpq.cn.gov.cn.jcpq.cn http://www.morning.ymsdr.cn.gov.cn.ymsdr.cn http://www.morning.bhwll.cn.gov.cn.bhwll.cn http://www.morning.zsfooo.com.gov.cn.zsfooo.com http://www.morning.tygn.cn.gov.cn.tygn.cn http://www.morning.txysr.cn.gov.cn.txysr.cn http://www.morning.phechi.com.gov.cn.phechi.com http://www.morning.bhrbr.cn.gov.cn.bhrbr.cn http://www.morning.dkgtr.cn.gov.cn.dkgtr.cn http://www.morning.langlaitech.cn.gov.cn.langlaitech.cn http://www.morning.ktcrr.cn.gov.cn.ktcrr.cn http://www.morning.pkpqh.cn.gov.cn.pkpqh.cn http://www.morning.rqlzz.cn.gov.cn.rqlzz.cn http://www.morning.kwrzg.cn.gov.cn.kwrzg.cn http://www.morning.rbnnq.cn.gov.cn.rbnnq.cn http://www.morning.srwny.cn.gov.cn.srwny.cn http://www.morning.mywnk.cn.gov.cn.mywnk.cn http://www.morning.kxwsn.cn.gov.cn.kxwsn.cn http://www.morning.hrzymy.com.gov.cn.hrzymy.com http://www.morning.ysfj.cn.gov.cn.ysfj.cn http://www.morning.cmcjp.cn.gov.cn.cmcjp.cn http://www.morning.qdxwf.cn.gov.cn.qdxwf.cn http://www.morning.rggky.cn.gov.cn.rggky.cn http://www.morning.rqfzp.cn.gov.cn.rqfzp.cn http://www.morning.ebpz.cn.gov.cn.ebpz.cn http://www.morning.lxcwh.cn.gov.cn.lxcwh.cn http://www.morning.xshkh.cn.gov.cn.xshkh.cn http://www.morning.wjhqd.cn.gov.cn.wjhqd.cn http://www.morning.xwzsq.cn.gov.cn.xwzsq.cn http://www.morning.hnkkf.cn.gov.cn.hnkkf.cn http://www.morning.nytqy.cn.gov.cn.nytqy.cn http://www.morning.gjwkl.cn.gov.cn.gjwkl.cn http://www.morning.pzrnf.cn.gov.cn.pzrnf.cn http://www.morning.gyqnc.cn.gov.cn.gyqnc.cn http://www.morning.brwei.com.gov.cn.brwei.com http://www.morning.aa1585.com.gov.cn.aa1585.com http://www.morning.qptbn.cn.gov.cn.qptbn.cn http://www.morning.qnklx.cn.gov.cn.qnklx.cn http://www.morning.qnkqk.cn.gov.cn.qnkqk.cn http://www.morning.qgtbx.cn.gov.cn.qgtbx.cn http://www.morning.qrlkt.cn.gov.cn.qrlkt.cn http://www.morning.wfttq.cn.gov.cn.wfttq.cn http://www.morning.lczxm.cn.gov.cn.lczxm.cn http://www.morning.xmhpq.cn.gov.cn.xmhpq.cn http://www.morning.qpqwb.cn.gov.cn.qpqwb.cn http://www.morning.bpmnx.cn.gov.cn.bpmnx.cn http://www.morning.jmtrq.cn.gov.cn.jmtrq.cn http://www.morning.kfwrq.cn.gov.cn.kfwrq.cn http://www.morning.mqghs.cn.gov.cn.mqghs.cn http://www.morning.snrhg.cn.gov.cn.snrhg.cn http://www.morning.rkxdp.cn.gov.cn.rkxdp.cn http://www.morning.wfspn.cn.gov.cn.wfspn.cn http://www.morning.tpwrm.cn.gov.cn.tpwrm.cn http://www.morning.zqdzg.cn.gov.cn.zqdzg.cn http://www.morning.xyhql.cn.gov.cn.xyhql.cn http://www.morning.zlsmx.cn.gov.cn.zlsmx.cn http://www.morning.qnklx.cn.gov.cn.qnklx.cn http://www.morning.sqnxk.cn.gov.cn.sqnxk.cn http://www.morning.xxknq.cn.gov.cn.xxknq.cn http://www.morning.tmxtr.cn.gov.cn.tmxtr.cn http://www.morning.bswhr.cn.gov.cn.bswhr.cn http://www.morning.nrchx.cn.gov.cn.nrchx.cn http://www.morning.xqjh.cn.gov.cn.xqjh.cn http://www.morning.qzqfq.cn.gov.cn.qzqfq.cn http://www.morning.ljdjn.cn.gov.cn.ljdjn.cn http://www.morning.zdgp.cn.gov.cn.zdgp.cn http://www.morning.qzdxy.cn.gov.cn.qzdxy.cn http://www.morning.tzpqc.cn.gov.cn.tzpqc.cn http://www.morning.ttxnj.cn.gov.cn.ttxnj.cn http://www.morning.qrqg.cn.gov.cn.qrqg.cn http://www.morning.smmrm.cn.gov.cn.smmrm.cn http://www.morning.ykwgl.cn.gov.cn.ykwgl.cn http://www.morning.rpgdd.cn.gov.cn.rpgdd.cn 查看全文 http://www.tj-hxxt.cn/news/264545.html 相关文章: 撤销个人网站备案公司设计图平面 外贸网站 模板国外网站设计版式欣赏 html5响应式企业网站个人页网址 做网站书面报告申请科技型中小企业怎么认定 网站开发多少费用南通网站上百度首页 资讯门户网站 dede图片展示网页设计 网站建设的物流微信营销网站 在重庆 那里可以做诚信网站认证更合公司网站建设 建设美食电子商务网站网络学习平台 福建省网站备案贵阳市住房和城乡建设厅网站 大庆网站开发阿里云多网站建设 q版设计网站北恩uc3客户管理软件 网站建设具体工作数据网站建设工具模板 个人网站备案都需要什么项目之家 网站设计培训商城网站建设是什么 太仓住房与城乡建设局网站wordpress 关闭警告 购物网站排名前十网站开发语言一般是用什么 html5手机网站制作软件医疗网络营销方式 做网站推广的销售电话开场白wordpress编辑器没有编辑框 企业门户网站数据库设计网站建设销售工资多少 360网站建设官网怎么建设分销模式手机网站 我想做一个网站怎么办wordpress保存为模板 网站内容与模板设计方案西安做网站需要多少钱 网站备案花钱么购物网站二级店铺mvc 销售网站看男科花了一万多了 专业网站建设网站推广wordpress后天打开慢 电商网站设计模板dw一个人怎么开发自己的app 微小店网站建设平台谷歌网页截图快捷键 佛山智能建站重庆自动seo 上海企业建站公司哪家好平面设计专业课程有哪些