| https://leetcode.com/problems/remove-outermost-parentheses | Easy |
|---|
fun removeOuterParentheses(s: String): String {
val result = StringBuilder()
var balance = 0
for (c in s) {
// Уменьшаем баланс перед добавлением закрывающей скобки
if (c == ')') balance--
// Добавляем символ, если он не является внешней скобкой
if (balance > 0) result.append(c)
// Увеличиваем баланс после добавления открывающей скобки
if (c == '(') balance++
}
return result.toString()
}