-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLC_1021.cpp
More file actions
34 lines (34 loc) · 750 Bytes
/
LC_1021.cpp
File metadata and controls
34 lines (34 loc) · 750 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
34
class Solution {
public:
string removeOuterParentheses(string S) {
int i,len=S.length(),left=0,flag=0;
string res="",ans="";
for(i=0;i<len;i++)
{
if((S[i]=='(')&&(flag==0))
{
left++;
flag=1;
}
else if(S[i]=='(')
{
res=res+S[i];
left++;
}
else if(S[i]==')')
{
left--;
if(left>0)
res=res+')';
else if(left==0)
{
flag=0;
if(res!="")
ans=ans+res;
res="";
}
}
}
return ans;
}
};