Skip to content

Commit

Permalink
Create MinimumAddtoMakeParenthesesValid.cpp
Browse files Browse the repository at this point in the history
Medium
  • Loading branch information
Rahuldandotiya committed Apr 20, 2020
1 parent 8485d65 commit e3f0748
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions MinimumAddtoMakeParenthesesValid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
public:
int minAddToMakeValid(string s) {
int count=0;
int i=0;
stack<char> st;
while(i<s.length()){
if(s[i]=='(') st.push(s[i]);
else{
if(!st.empty() and st.top()=='(') st.pop();
else count++;
}
i++;
}
count+=st.size();
return count;
}
};

0 comments on commit e3f0748

Please sign in to comment.