Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int minAddToMakeValid(string S) {
- int open, ans;
- open = ans = 0;
- for(char c: S){
- if(c == '(') open++;
- if(c == ')' && !open) ans++;
- if(c == ')' && open) open--;
- }
- ans += open;
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement