Skip to content

Commit 10ea9c3

Browse files
committed
Add 921-MinimumAddToMakeParenthesesValid.cpp
1 parent 88f1451 commit 10ea9c3

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public:
3+
int minAddToMakeValid(string s) {
4+
int f(0), cnt(0);
5+
for(int p = 0; p < s.size(); p++){
6+
f += (s[p] == '(') - (s[p] == ')');
7+
if(f < 0){++cnt; f = 0;}
8+
}
9+
10+
return cnt + f;
11+
}
12+
};

0 commit comments

Comments
 (0)