O(n) ->time complexity and O(1) -> space complexity Easy to understand


#1

just count the mismatch and then add them
int Solution::solve(string A) {
int a=0,b=0;
for(int i=0;i<A.length();i++)
{
if(A[i]==’(’)
{
a++;
}
else
{
if(a==0)
b++;
else
a–;
}

}
return b+a;

}