Leetcode Note: Go - Remove Outermost Parentheses
Remove Outermost Parentheses - LeetCode
https://leetcode.com/problems/remove-outermost-parentheses/
- Go 言語で取り組んだメモ
回答
Simple Go and Java solutions - LeetCode Discuss
https://leetcode.com/problems/remove-outermost-parentheses/discuss/1045167/Simple-Go-and-Java-solutions
func removeOuterParentheses(S string) string {
s := ""
h := []string{}
for _, i2 := range S {
if string(i2) == "(" {
if len(h) != 0 {
s += "("
}
h = append(h, "(")
} else {
if len(h) != 1 {
s += ")"
}
h = h[:len(h)-1]
}
}
return s
}