1021.删除最外层的括号
/*
* @lc app=leetcode.cn id=1021 lang=typescript
*
* [1021] 删除最外层的括号
*/
// @lc code=start
function removeOuterParentheses(s: string): string {
let stack = [];
let final: string[] = [];
let l = 0,
r = 0;
while (r < s.length) {
if (s[r] == "(") {
stack.push(1);
} else {
stack.pop();
}
if (stack.length == 0) {
// 结束
final.push(s.slice(l + 1, r));
l = r + 1;
}
r++;
}
console.log(final);
return final.join("");
}
console.log(removeOuterParentheses("(()())(())"));
// @lc code=end
小于 1 分钟
