#include<bits/stdc++.h>
using namespace std;
bool check(string str) {
stack s;
for(int i=0;i<str.size();i++){
char cur = str[i];
if(cur == β(β){
s.push(cur);
}
else if(cur == β)β){
if(s.empty() || s.top()!=β(β){
return false;
}
s.pop();
}
}
return s.empty();
}
int main(){
string s;
cin>>s;
if(check(s)){
cout<<βYesβ<<endl;
}
else{
cout<<βNoβ<<endl;
}
}
Balanced paranthesis program is failing one test case
You are not considering [ ans { brackets
Even considering it also its getting failed
Give ur updated code.
this is failing two test cases
#include<bits/stdc++.h>
using namespace std;
bool check(string str) {
stack s;
for(int i=0;i<str.size();i++){
char cur = str[i];
if(cur == β(β || cur == β[β){
s.push(cur);
}
else if(cur == β)β || cur == β]β){
if(s.empty() || s.top()!=β(β || s.top()!=β[β){
return false;
}
s.pop();
}
}
return s.empty();
}
int main(){
string s;
cin>>s;
if(check(s)){
cout<<βYesβ<<endl;
}
else{
cout<<βNoβ<<endl;
}
}