Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
601 B
3
Indexable
Never
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;
}