Easiest and simplest solution in C++


#1

int Solution::solve(string A) {

    stack<char> s;

    for(int i=0;i<A.length(); i++)

    {

        if(A[i]==’(’)

            s.push(A[i]);

        else{                               // if ‘)’

            if(s.empty())        //not valid

                return 0;                  

            else

                s.pop();

        }

    }

    return s.empty()? 1 :0 ;

}