文章
17
粉丝
0
获赞
5
访问
1.3k
//1067题的代码稍微改一点就行。主要两点不同:①只有两个类型的括号②括号没有优先级
//解题思路:map映射字符为整数,结合数据结构的stack进行括号匹配。
#include<iostream>
#include<map>
#include<stack>
using namespace std;
map<char,int> Bracket={{'[',-2},{'(',-1},{')',1},{']',2}};
bool match(const string &str){
bool flag=true;
stack<char> S;
for(int i=0;i<str.length();i++){
if(S.empty()){
if(Bracket[str[i]]>0){
flag=false;
break;
}
else S.push(str[i]);
}
&nb...
登录后发布评论
暂无评论,来抢沙发