Skip to content

Commit 86b7316

Browse files
Create minimum_add_to_make_parantheses_valid.cpp
1 parent 840b1c6 commit 86b7316

File tree

1 file changed

+17
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)