# 删除无效的括号
给你一个由若干括号和字母组成的字符串 s
,删除最小数量的无效括号,使得输入的字符串有效。
返回所有可能的结果。答案可以按 任意顺序 返回。
示例 1:
输入:s = "()())()"
输出:["(())()","()()()"]
示例 2:
输入:s = "(a)())()"
输出:["(a())()","(a)()()"]
示例 3:
输入:s = ")("
输出:[""]
提示:
1 <= s.length <= 25
s
由小写英文字母以及括号 '('
和 ')'
组成
s
中至多含 20
个括号
## template
```cpp
#include
using namespace std;
class Solution
{
public:
vector removeInvalidParentheses(string s)
{
vector ans;
rm(move(s), ans, {'(', ')'}, 0, 0);
if (ans.empty())
return {""};
return ans;
}
void rm(string s, vector &ans, vector brackets, int sea_i, int del_i)
{
int sta = 0;
for (int i = sea_i; i < s.size(); i++)
{
if (s[i] == brackets[0])
sta++;
else if (s[i] == brackets[1])
{
sta--;
if (sta < 0)
{
for (int j = del_i; j <= i; j++)
{
if (s[j] == brackets[1] && (j == del_i || s[j - 1] != brackets[1]))
{
string new_s = s.substr(0, j) + s.substr(j + 1);
rm(move(new_s), ans, brackets, i, j);
}
}
return;
}
}
}
reverse(s.begin(), s.end());
if (brackets[0] == '(')
rm(move(s), ans, {brackets[1], brackets[0]}, 0, 0);
else
ans.push_back(move(s));
}
};
```
## 答案
```cpp
```
## 选项
### A
```cpp
```
### B
```cpp
```
### C
```cpp
```