func valid(stack []rune) bool {
var _s []rune
for _, p := range stack {
if p == '(' {
_s = append(_s, p)
} else {
if _s[len(_s)-1] == '(' {
_s = _s[:len(_s)-1]
}
}
}
return len(_s) == 0
}
func removeOuterParentheses(s string) string {
var stack []rune
var ans string
for _, p := range s {
stack = append(stack, p)
if valid(stack) {
for _, _p := range stack[1:len(stack)-1] {
ans += string(_p)
}
stack = nil
}
}
return ans
}