-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1249.cpp
More file actions
33 lines (33 loc) · 756 Bytes
/
1249.cpp
File metadata and controls
33 lines (33 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Solution {
public:
string minRemoveToMakeValid(string s) {
int left=0;
int right=0;
vector<char>st;
for(int i=0;i<s.size();i++){
if(s[i]=='('){
left++;
}
else if(s[i]==')'){
if(right>=left){
continue;
}
right++;
}
st.push_back(s[i]);
}
string str1;
while(right<left){
int x=st.size()-1;
while(st[x]!='('){
x--;
}
st.erase(st.begin()+x);
left--;
}
for(int i=0;i<st.size();i++){
str1+=st[i];
}
return str1;
}
};