class Solution {
public:
stack<int>_stack;
vector<int> pos;
string strs;
string removeOuterParentheses(string S) {
strs = "";
for(int i = 0 ; i < S.size(); i++)
{
if( S[i] == '(' )
{
if(_stack.empty())
{
pos.push_back(i);
}
_stack.push(i);
}
else if(S[i] == ')')
{
if(_stack.size() == 1)
{
pos.push_back(i);
}
_stack.pop();
}
}
for(int i = 0 ; i < pos.size() ; i+=2)
{
string str = S.substr(pos[i] +1, (pos[i+1] - pos[i]) - 1 );
strs+=str;
}
return strs;
}
};