Untitled
unknown
plain_text
2 years ago
601 B
10
Indexable
bool findRedundantBrackets(string &s)
{
stack<char> stack;
for(auto i:s){
if(i=='(' || i=='+' || i=='-' || i=='*' || i=='/') {
stack.push(i);
}else if(i==')'){
char isR=true;
while(stack.top()!='(' && !stack.empty()){
char t=stack.top();
if (t=='+' || t=='-' || t=='*' || t=='/') isR=false;;
stack.pop(); //remove operator
}
if(isR==true) return true;
stack.pop(); //remove op brackets
}
}
return false;
}
Editor is loading...