Solution with the help of stack


#1

int Solution::solve(string A) {
stack s;
int k=0;
for(int i=0;i<A.length();i++){
if(A[i]==’(’){
s.push(A[i]);
}
else{
if(!s.empty()){
s.pop();
}
else{
k+=1;
}
}
}
return s.size()+k;
}