1021. Remove Outermost Parentheses
4ms 94.26%
class Solution {
public:
string removeOuterParentheses(string S) {
int count=1,beg=0;
string ans;
for(int i=1;i<S.size();i++){
if(S[i]=='(')count++;
if(S[i]==')')count--;
if(count==0){
string tmp=S.substr(beg,i-beg+1);
tmp=tmp.substr(1,tmp.size()-2);
ans+=tmp;
beg=i+1;
}
}
return ans;
}
};