代码同Leetcode 301 中的预处理
class Solution {
public:
int minAddToMakeValid(string S) {
int l = 0, r = 0;
for (auto &c : S){
if (c == '(') l++;
else{
if (l) l--;
else r++;
}
}
return l + r;
}
};