Skip to content

Commit 4f2d700

Browse files
authored
Create 921. Minimum Add to Make Parentheses Valid (#609)
2 parents eff2af5 + 44abfd5 commit 4f2d700

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
4+
int minAddToMakeValid(string s) {
5+
stack<char> stac;
6+
for(char c : s)
7+
{
8+
if(!stac.empty() && stac.top()=='(' && c==')')stac.pop();
9+
else stac.push(c);
10+
}
11+
return stac.size();
12+
}
13+
};

0 commit comments

Comments
 (0)