调试中...
调试中...
题目描述
题目描述
题解
题解
提交记录
提交记录
代码
代码
测试用例
测试用例
测试结果
测试结果
困难
相关标签
相关企业
提示

给你一个由若干括号和字母组成的字符串 s ,删除最小数量的无效括号,使得输入的字符串有效。

返回所有可能的结果。答案可以按 任意顺序 返回。

 

示例 1:

输入:s = "()())()"
输出:["(())()","()()()"]

示例 2:

输入:s = "(a)())()"
输出:["(a())()","(a)()()"]

示例 3:

输入:s = ")("
输出:[""]

 

提示:

  • 1 <= s.length <= 25
  • s 由小写英文字母以及括号 '('')' 组成
  • s 中至多含 20 个括号
通过次数
117.7K
提交次数
211.6K
通过率
55.6%


相关企业

提示 1
Since we do not know which brackets can be removed, we try all the options! We can use recursion.

提示 2
In the recursion, for each bracket, we can either use it or remove it.

提示 3
Recursion will generate all the valid parentheses strings but we want the ones with the least number of parentheses deleted.

提示 4
We can count the number of invalid brackets to be deleted and only generate the valid strings in the recusrion.


评论 (0)

贡献者
© 2025 领扣网络(上海)有限公司
0 人在线
行 1,列 1
s =
"()())()"
Source