class Solution {
public int minAddToMakeValid(String s) {
int l=0,res=0;
for (int i = 0; i <s.length() ; i++) {
char c=s.charAt(i);
if(c=='('){
l++;
}else{
if(l>0){
l--;
}else{
res++;
}
}
}
return res+l;
}
}