Redundant Braces

int Solution::braces(string A) {
    stack<char> s;
    
    
    for(char ch: A) {
        if(ch == '(' || ch == '+' || ch == '-' || ch == '*' || ch == '/')
            s.push(ch);
        else if(ch == ')' && !s.empty() && s.top() == '(') 
            return true;
        else if(ch == ')') {
            while(!s.empty() && s.top() != '(')
                s.pop();
            s.pop();
        }
    }
    return false;
}

Last updated